akshay1234 Posted April 11, 2011 Share Posted April 11, 2011 i'm trying to send across a very simple query to mysql through php, but cannot get the variables to work. the php error i receive is "Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\XAMPP\xampp\htdocs\oauth\login\checklogin.php on line 20" i'm trying to update a field named "last_accessed" in the table. i have the connection down, and the database is all set. // time to update timestamp of LAST ACCESSED $timestamp = date("l F d, Y, h:i A"); mysql_query("UPDATE members SET last_accessed = "$timestamp" WHERE myusername = "$mygivenusername" AND mypassword = "$mygivenpassword""); earlier on in the code, $mygivenusername and $mygivenpassword are defined through a POST form. that works ok. btw the mysql_query line is line #20. thanks (: Quote Link to comment https://forums.phpfreaks.com/topic/233390-help-with-variables-in-mysql-query/ Share on other sites More sharing options...
akshay1234 Posted April 11, 2011 Author Share Posted April 11, 2011 and if it helps... Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1 MySQL client version: mysqlnd 5.0.7-dev - 091210 - $Revision: 304625 $ Quote Link to comment https://forums.phpfreaks.com/topic/233390-help-with-variables-in-mysql-query/#findComment-1200198 Share on other sites More sharing options...
Pikachu2000 Posted April 11, 2011 Share Posted April 11, 2011 Within a string, you can't use the same type of quotes that enclose a string without escaping them. Either change the inner double quotes to single quotes, or escape them with backslashes. Also, why would you not just use a DATETIME field in the table, and use MySQL's NOW() function to insert the timestamp? Using the format you're using makes it rather difficult to do any comparisons or calculations with the timestamps. Quote Link to comment https://forums.phpfreaks.com/topic/233390-help-with-variables-in-mysql-query/#findComment-1200200 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.