php - MySQL Update Syntax -
i'm trying write mysql in php script update field in database error:
fatal error: wrong sql: error: have error in sql syntax; check manual corresponds mysql server version right syntax use near ''user' set 'currentsong' = '' 'userid' = '1893''
while using code.
$setcurrentsongsql = "update 'user' set 'currentsong' = '$currentsong' 'userid' = '$sql1'"; $setcurrentsong = $db->query($setcurrentsongsql);
i'm sure it's simple i'm baffled. if replace variables normal string doesn't work.
thank in advance help.
mysql uses backtick ` column , table names, , apostrophes ' string constants. these aren't needed unless you're using reserved keyword (such table called "table") or table or column name contains spaces (such "my table").
you can use:
$setcurrentsongsql = "update `user` set `currentsong` = '$currentsong' `userid` = '$sql1'";
or:
$setcurrentsongsql = "update user set currentsong = '$currentsong' userid = '$sql1'";
also, if $currentsong
comes untrusted source, might want worry sql injection.
Comments
Post a Comment