Jump to content

Change snippet to use CURDATE


codeboy89

Recommended Posts

I am using time() in the snippet below, I would like to use CURDATE() and have the database setup for date. My problem is, I am not sure how to change the PHP coding, I keep getting errors just adding CURDATE() where time() is. Any help would be greatly appreciated...

 

 

        $update = mysql_query("UPDATE comments SET comment='".$comment."',created_at='".time()."' WHERE user_id=".$_SESSION['logged_id']);

 

      } else {

 

        $insert = mysql_query("INSERT INTO comments(`id`,`user_id`,`comment`,`created_at`) VALUES(0,".$_SESSION['logged_id'].",'".$comment."','".time()."')");

Link to comment
https://forums.phpfreaks.com/topic/179468-change-snippet-to-use-curdate/
Share on other sites

CURDATE() is MySQL's function, while time() is PHP's, so you have to put it inside double quotes, not outside.

 

$update = mysql_query("UPDATE comments SET comment='".$comment."',created_at=CURDATE() WHERE user_id=".$_SESSION['logged_id']);

      } else {

         $insert = mysql_query("INSERT INTO comments(`id`,`user_id`,`comment`,`created_at`) VALUES(0,".$_SESSION['logged_id'].",'".$comment."',CURDATE())");

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.