DarrenReeder Posted December 5, 2009 Share Posted December 5, 2009 I have made a updates page on my site and you can type into the form and it sends it to a database e.t.c. this is what i have for when i send the data: //get data $title = $_POST['title']; $body = $_POST['body']; $date = date(Y-m-d); //insert data $insert = mysql_query("INSERT INTO News SET title='$title', body='$body', date='$date' ") or die(mysql_error()); that is what i have and it all works fine expect for the Date always looks like 0000-00-00 and i dont know how to fix this.. If anyone could help out on why it always looks like that (it says 0000-00-00 in the database aswell as on the page, so im pretty sure its a PHP problem) Quote Link to comment https://forums.phpfreaks.com/topic/184077-date-function-not-working/ Share on other sites More sharing options...
rajivgonsalves Posted December 5, 2009 Share Posted December 5, 2009 you forgot the quotes $date = date('Y-m-d'); Quote Link to comment https://forums.phpfreaks.com/topic/184077-date-function-not-working/#findComment-971823 Share on other sites More sharing options...
oni-kun Posted December 5, 2009 Share Posted December 5, 2009 I have made a updates page on my site and you can type into the form and it sends it to a database e.t.c. this is what i have for when i send the data: //get data $title = $_POST['title']; $body = $_POST['body']; $date = date(Y-m-d); //insert data $insert = mysql_query("INSERT INTO News SET title='$title', body='$body', date='$date' ") or die(mysql_error()); that is what i have and it all works fine expect for the Date always looks like 0000-00-00 and i dont know how to fix this.. If anyone could help out on why it always looks like that (it says 0000-00-00 in the database aswell as on the page, so im pretty sure its a PHP problem) $date is a variable, so you must use double quotations: //insert data $insert = mysql_query("INSERT INTO News SET title='$title', body='$body', date=$date ") or die(mysql_error()); EDDIT: Nevermind, didn't see the first problem. Quote Link to comment https://forums.phpfreaks.com/topic/184077-date-function-not-working/#findComment-971824 Share on other sites More sharing options...
DarrenReeder Posted December 5, 2009 Author Share Posted December 5, 2009 aha, thankyou - its working Quote Link to comment https://forums.phpfreaks.com/topic/184077-date-function-not-working/#findComment-971828 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.