Jump to content

Need Help INSERTing Time in to mySQL.


wezly

Recommended Posts

hey, here is the code I am using.

 

mysql_connect("localhost","XXXXXX","XXXXXX") or die("Could not connect.");
mysql_select_db("XXXXXX");

$query="SELECT * FROM VIDEO_SESSIONS";
$result=mysql_query($query);

while ($db_field = mysql_fetch_assoc($result)) {
$timeslider = $db_field['timeslider'];
}

$message=$_POST['message'];

$name=$me['first_name']; 

if(isset($_POST['submit'])){

    if(strlen($message)<1)

   {
      print "You did not input a message";
   }

   else if(strlen($name)<1)

   {
      print "Please login with Facebook to post a message";
   }

  
      else

      {


         $insertmessage="INSERT INTO CHAT_SESSIONS 
					 (user_id,user_message,current_time) 
					 VALUES
					 ('$name', '$message', '$timeslider')";
         mysql_query($insertmessage);
         echo mysql_error();


      }

   }


?>

 

I am getting this error everytime I try and INSERT into the database

 

" You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'current_time) VALUES ('Luke', 'Hello?', '00:23:00')' at line 2 "

 

it works fine without the '$timeslider' which is a time stored on the database in the format 00:00:00

why does it not want to store the time back in a different table.. same format!?

Link to comment
https://forums.phpfreaks.com/topic/217467-need-help-inserting-time-in-to-mysql/
Share on other sites

current_time, the point in the query that is being called out in the error message, is a reserved mysql keyword.

 

You either need to rename your column or enclose that in back-ticks `` every time you use it in a query.

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.