Jump to content

Date() Function not working?


DarrenReeder

Recommended Posts

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)

Link to comment
https://forums.phpfreaks.com/topic/184077-date-function-not-working/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.