Page 1 of 1

Update MySQL Entry

Posted: Fri Nov 28, 2003 1:55 pm
by partiallynothing
I want to update the datbase for the specified user with the new "last login" date.

Code: Select all

<?php
		$query = "UPDATE lastvisit SET $currentdate FROM users WHERE username = $username AND password = $password";
		$resut = mysql_query($query) or die(mysql_error());
?>
I get an error with the above code thats soemthing along the lines of "You have an error in your SQL syntax near '2003-11-28 FROM users WHERE username ='username' AND password = 'password'' at line 1"

Am I using incorect syntax. Thanks!

Posted: Fri Nov 28, 2003 2:06 pm
by microthick
My code assumes that the table is called users, the field is called lastvisit, and the current date is $currentdate:

Code: Select all

<?php
      $query = "UPDATE users SET lastvisit = $currentdate WHERE username = $username AND password = $password";
      $resut = mysql_query($query) or die(mysql_error());
?>

Posted: Sat Nov 29, 2003 5:34 pm
by JAM
Also, be sure to add ' around the values when inserting/updating etc., fields in the database to start with. Some more reading up on functions to be using with this might be for example: mysql_escape_string()

Code: Select all

$query = "UPDATE users SET lastvisit = '$currentdate' WHERE username = '$username' AND password = '$password'";
      $resut = mysql_query($query) or die(mysql_error());