I have a SQL error below when I run my PHP SQL code:
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 'WHERE useid = 8' at line 1
mysql_query("UPDATE free_ebook SET math = $assign_math WHERE useid = $newuserid;")or die(mysql_error());
The math
field is int(10)
, and useid
is also int(10)
.
Looks like the field name should probably be userid
, not useid
.
Alternatively, try enclosing the values in single quotes, like this:
"UPDATE free_ebook SET math = '".$assign_math."' WHERE useid = '".$newuserid."';"
or even
"UPDATE free_ebook SET math = '{$assign_math}' WHERE useid = '{$newuserid}';"
On the topic: mysql_query()
is deprecated, you should be using the PDO extension. It's easy (maybe easier!) to learn and a lot more secure:
Are there good tutorials on how to use PDO?
http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers
http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/