Jump to content

Timestamp problem


angelssin

Recommended Posts

hi, i already posted this problem in my older topic, but no one seems to be checking that out...anyway, heres my problem.

 

i got everything working on my blog system now...except for the date. Basically i want to store the date of the post into my date field in my mysql database, however...whenever i post anything it just keeps coming up with the default Date: 0000-00-00 00:00:00 I'll post my code for it below...however, i understand that there may be something wrong with my date field in my database so could you please tell me which settings to use for that field.

 

<?

 

$dbServer=mysql_connect("localhost","username","password");

    if (!$dbServer) {echo "Failed to connect to MySQL"; exit; }

 

    mysql_select_db("username_reviews",$dbServer);

 

$date="SELECT CURRENT_TIMESTAMP";

$sql="INSERT INTO reviews (id, title, comment, date) VALUES ('$_POST[id]','$_POST[title]','$_POST[commentsBox]','$date')";

 

if (!mysql_query($sql,$dbServer))

  {

  die('Error: ' . mysql_error());

  }

echo "your comment has been posted";

 

mysql_close($dbServer)

?>

 

thanks a lot...again any help at all is really appreciated. this has been doing my head in for hours again :(

Link to comment
https://forums.phpfreaks.com/topic/45698-timestamp-problem/
Share on other sites

$date="SELECT CURRENT_TIMESTAMP"; is nonsense, I'm afraid.

 

You would save uour head being done in for hours on end by looking at a simple database tutorial. Meantine, try something like:

 

$date = date(Y-m-d);

 

or

 

$date = date(Y-m-d h:i:s);

 

Avoid all temptations to 'format' the entered date into some bizarre order .. you can do that when you retrieve it. Details on that at php.net for the function date()

Link to comment
https://forums.phpfreaks.com/topic/45698-timestamp-problem/#findComment-222028
Share on other sites

its still coming up with the default 0's. Do you know what my settings should be for my date field? at the moment its as follows. (as it looks in php myadmin)

 

Field: date Type: datetime Collation: (empty) Attributes: (empty) Null: No Default: 0000-00-00 00:00:00 Extra: (empty)

 

i cant think of any other reason for the time not saving to the database than there being a problem with the date field. I'm just lost on this.

Link to comment
https://forums.phpfreaks.com/topic/45698-timestamp-problem/#findComment-222109
Share on other sites

brilliant...i thought for a second that i might have needed quotation marks, but i was putting them outside of the brackets...thanks a lot again, i promise to take everything new that i learn on board on not just be one of these people who copies and pastes other peoples code :)

Link to comment
https://forums.phpfreaks.com/topic/45698-timestamp-problem/#findComment-222118
Share on other sites

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.