weemikey Posted July 25, 2007 Share Posted July 25, 2007 Hi all. I don't think I will ever understand where the single vs. double quotes should go. I have this query that is giving me a sql syntax error at the "theme_id" $sql = "UPDATE theme SET theme.img_file = '".$newname."' WHERE theme.id = '".$theme_id."'"; I've tried every permutation and combination I could think of. I still get the error. It's THREE lines of freakin' code? Is it obvious to anyone else what I'm missing? Is there a reference somewhere that explains where the quotes go and why? Link to comment https://forums.phpfreaks.com/topic/61666-its-late-and-i-dont-know-what-the-hell-is-wrong-with-the-quotes-in-this/ Share on other sites More sharing options...
GingerRobot Posted July 25, 2007 Share Posted July 25, 2007 Make your life a lot simpler: $sql = "UPDATE theme SET theme.img_file = '$newname' WHERE theme.id = '$theme_id'"; Its so early for me to come up with a coherent explanation of the quotes though. Im sure i would just confuse the issue. Link to comment https://forums.phpfreaks.com/topic/61666-its-late-and-i-dont-know-what-the-hell-is-wrong-with-the-quotes-in-this/#findComment-306962 Share on other sites More sharing options...
weemikey Posted July 25, 2007 Author Share Posted July 25, 2007 You are an officer and a gentleman. However this is what I get when I run that code: check the manual that corresponds to your MySQL server version for the right syntax to use near '6'.jpg' WHERE theme.id = ''6''' So, is my $theme_id coming IN with quotes on it? Is that the problem? Right above this sql I name a file (we're uploading avatars here). // name the file with img + the member_id + the extension (.jpg etc) $newname = "img/th_".$theme_id.$ext; So, if the filename in the error is '6'.jpg, how do I stop the theme_id from having single quotes on it? So confusing! Link to comment https://forums.phpfreaks.com/topic/61666-its-late-and-i-dont-know-what-the-hell-is-wrong-with-the-quotes-in-this/#findComment-306967 Share on other sites More sharing options...
GingerRobot Posted July 25, 2007 Share Posted July 25, 2007 I really cant think why you would get a quote there - it should be an integer variable. Can you show how/where youdefine $theme_id? Also, just to make 100% certain this is the problem, try modifying your or die statement(which, presumably you already have hence the above error) $sql = "UPDATE theme SET theme.img_file = '".$newname."' WHERE theme.id = '".$theme_id."'"; mysql_query($sql) or die(mysql_error().'<br />Query: '.$sql); Link to comment https://forums.phpfreaks.com/topic/61666-its-late-and-i-dont-know-what-the-hell-is-wrong-with-the-quotes-in-this/#findComment-306975 Share on other sites More sharing options...
simcoweb Posted July 25, 2007 Share Posted July 25, 2007 In your SQL syntax, try naming the field/column names. That's probably throwing your error. Like this: $sql = "UPDATE theme (col1, col2) SET theme.img_file = '$newname' WHERE theme.id='$theme_id'"; Replace col1, col2 with the actual column names. Let me know what happens. Link to comment https://forums.phpfreaks.com/topic/61666-its-late-and-i-dont-know-what-the-hell-is-wrong-with-the-quotes-in-this/#findComment-306995 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.