HTML form date picker not populating mysql database

Please help me. I have a html form with a date picker named “form.html”- here’s the code -

  • Date / MM / DD YYYY
    	<span id="calendar_1">
    		<img id="cal_img_1" class="datepicker" src="calendar.gif" alt="Pick a date.">	
    	</span>
    	<script type="text/javascript">
    		Calendar.setup({
    		inputField	 : "element_1_3",
    		baseField    : "element_1",
    		displayArea  : "calendar_1",
    		button		 : "cal_img_1",
    		ifFormat	 : "%B %e, %Y",
    		onSelect	 : selectDate
    		});
    	</script>
    

    The problem that I am having is writing the php script so that the date i select in the date picker with populate to my MySql database. The name of my php script page is NForms.php here is the code I have on it.

    $sql=“INSERT INTO ClassLeadersReport (element_1, element_2)
    VALUES
    (’$_POST[element_1]’,’$_POST[element_2]’)”;

    if (!mysql_query($sql,$con))
    {
    die('Error: ’ . mysql_error());
    }
    //echo “Record Added Successfully”;

    mysql_close($con)

    When I check my database - it just displays 0000 00 00 in the date field and 00.0 in the price field.

    Please assist me. Thank you so much for any suggestions. " I am a newbie to PHP "

  • First try to echo [php]echo $_POST[element_1]’; echo ‘$_POST[element_2]’[/php] in your php-script.

    If it displays the respective values then the error is in your database-table column-type, So, just change it to varchar(100) and try again.

    That will give you an error message.

    try excatly the same way mentioned below :
    [php]echo $_POST[‘element_1’] ; echo $_POST[‘element_2’];[/php]

    I have added single quote for element_1 and 2

    Sponsor our Newsletter | Privacy Policy | Terms of Service