Jump to content

It's late and I don't know what the hell is wrong with the quotes in this....


weemikey

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.