Pallchrn2 Posted April 23, 2012 Share Posted April 23, 2012 problem showing date posted from a form into MYSQL using the php code. Date shows as 0000-00-00 and not the value submitted from the form. Thank you for any help $sql="INSERT INTO Results (RunnerID, EventID, Date, FinishTime, Position, CategoryID, AgeGrade, PB) VALUES ('$_POST[RunnerID]','$_POST[EventID]','$_POST[Date]','$_POST[FinishTime]','$_POST[Position]','$_POST[CategoryID]','$_POST[AgeGrade]','$_POST[PB]')"; if (!mysql_query($sql,$connection)) { die('Error: ' . mysql_error()); } echo "<h1> Success! Saving data: </h1>"; mysql_close($connection); ?> <html> <head> <title>Submitted</title> </head> <body> <br /> <?php echo "RunnerID=" . $_POST["RunnerID"]; ?><br /> <?php echo "EventID=" . $_POST["EventID"]; ?><br /> <?php echo "Date=" . $_POST["Date"]; ?><br /> <?php echo "FinishTime=" . $_POST["FinishTime"]; ?><br /> <?php echo "Position=" . $_POST["Position"]; ?><br /> <?php echo "CategoryID=" . $_POST["CategoryID"]; ?><br /> <?php echo "AgeGrade=" . $_POST["AgeGrade"]; ?><br /> <?php echo "Personal best=" . $_POST["PB"]; ?><br /> </body> </html> Quote Link to comment Share on other sites More sharing options...
mapleleaf Posted April 23, 2012 Share Posted April 23, 2012 What type of field are you using in Mysql and can you do a print_r of your post array before inserting to see what values it is holding? Quote Link to comment Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 You have to match MySQL's format of YYYY-MM-DD. You can use PHP's strtotime and date functions as seen here: http://stackoverflow.com/questions/3643499/convert-date-format-to-mysql-time-stamp Or you can do this within your query, using str_to_date http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date http://stackoverflow.com/questions/8453009/convert-a-date-string-into-proper-date-stamp-in-mysql-i-need-the-sql-code-not Quote Link to comment Share on other sites More sharing options...
Pallchrn2 Posted April 23, 2012 Author Share Posted April 23, 2012 The database is is using date format and the form is submitted y-m-d, i have echoed the date and it shows correct but not displayed on the MYSQL correctly. Quote Link to comment Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 Please, echo a query you'd execute with the correct data that ends up as '0000-00-00' echo $sql Quote Link to comment Share on other sites More sharing options...
Pallchrn2 Posted April 23, 2012 Author Share Posted April 23, 2012 When i echo sql I get INSERT INTO Results (RunnerID, EventID, Date, FinishTime, Position, CategoryID, AgeGrade, PB) VALUES ('1','1','2012-02-31','23:59:00','1','1','34.22','1') but in database still showing 0000-00-00 for date Quote Link to comment Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 2012-02-31 is an invalid date. There is no February 31. Change it to 2012-02-15 and it should work. Quote Link to comment Share on other sites More sharing options...
Pallchrn2 Posted April 23, 2012 Author Share Posted April 23, 2012 works thank you erm maybe need a better regex on my js code... any ideas please? Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 23, 2012 Share Posted April 23, 2012 You could use checkdate() on the php side to validate it before attempting to insert. Anything you validate with JS must ALSO be validated with PHP. Quote Link to comment Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 [edit] Jesi beat me Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 23, 2012 Share Posted April 23, 2012 I'm a ninja. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.