jakeruston Posted July 23, 2008 Share Posted July 23, 2008 Hi, I'm trying to run a MySQL Query: $update = "UPDATE `user` SET `weight` = 'weight' + $weight WHERE `username` = '$user'"; mysql_query($update) or die(mysql_error()); I get this error: 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 `username` = ''' at line 1 Any idea of why? Link to comment https://forums.phpfreaks.com/topic/116173-syntax-error/ Share on other sites More sharing options...
Orionsbelter Posted July 23, 2008 Share Posted July 23, 2008 well first the string should be $update = "UPDATE `user` SET `weight` = weight+$weight WHERE `username` = '$user'"; Link to comment https://forums.phpfreaks.com/topic/116173-syntax-error/#findComment-597402 Share on other sites More sharing options...
Orionsbelter Posted July 23, 2008 Share Posted July 23, 2008 try that see if it works and post back please Link to comment https://forums.phpfreaks.com/topic/116173-syntax-error/#findComment-597404 Share on other sites More sharing options...
paul2463 Posted July 23, 2008 Share Posted July 23, 2008 it is telling you that the query cannot run because the variable $user does not exist try echo out the query instead of running it and see what I mean try $update = "UPDATE `user` SET `weight` = 'weight' + $weight WHERE `username` = '$user'"; echo $update; you will find that there is no information for $user Link to comment https://forums.phpfreaks.com/topic/116173-syntax-error/#findComment-597405 Share on other sites More sharing options...
jakeruston Posted July 23, 2008 Author Share Posted July 23, 2008 Can't believe I messed that up guys, I spelt the variable wrong in the first place. Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/116173-syntax-error/#findComment-597493 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.