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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.