ChompGator Posted November 20, 2008 Share Posted November 20, 2008 I have a script that users fill out a simple form > it inserts into the database, but the date field is not submitting into the database...Well it is submitted, except the date is being inserted into the database as all zeros in this format 00-00-0000. Does anyone know why its submitting the date is submitting into my database in PHPMyAdmin like that? In PHPMyAdmin I have selected as "Date" from the drop down for the date field. Here is the script that inserts the values: Incase it helps - Note, Im not getting any errors submitting the only problem is the script is submitting the date as 00-00-0000 into the table in phpmyadmin <?php $con = mysql_connect("","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("legion", $con); $sql="INSERT INTO cadet_events (eventname, eventdate, eventdescription) VALUES ('$_POST[eventname]','$_POST[eventdate]','$_POST[eventdescription]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "The Event Has Been Added - Thank You"; mysql_close($con) ?> Link to comment https://forums.phpfreaks.com/topic/133452-problem-inserting-date/ Share on other sites More sharing options...
iversonm Posted November 20, 2008 Share Posted November 20, 2008 it means you $_POST['eventdate'] is not in the propper format.. i would do this instead $sql="INSERT INTO cadet_events (eventname, eventdate, eventdescription) VALUES ('$_POST[eventname]', NULL,'$_POST[eventdescription]')"; and then in your database change the type to timestamp and then under default check current timestamp so its filled in automatically if you dont know much about timestamp just look up date() in the php manual did that help at all? Link to comment https://forums.phpfreaks.com/topic/133452-problem-inserting-date/#findComment-694142 Share on other sites More sharing options...
ChompGator Posted November 21, 2008 Author Share Posted November 21, 2008 The date is still submitting into the database as 0000-00-00 Any thought Link to comment https://forums.phpfreaks.com/topic/133452-problem-inserting-date/#findComment-695010 Share on other sites More sharing options...
xtopolis Posted November 21, 2008 Share Posted November 21, 2008 Try some test queries with fake data: INSERT INTO cadet_events (eventname, eventdate, eventdescription) VALUES ('testEvent','2008-11-20','A test event'); ^-- Then check if mysql accepted it. If this works, the problem lies with your form. Post your form code, as well the php validation for the inputs. The format (at least for my date col) defaults to YYYY-MM-DD, so be sure you're supplying that in your form. Link to comment https://forums.phpfreaks.com/topic/133452-problem-inserting-date/#findComment-695057 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.