Jump to content

[SOLVED] Syntax Issue (Probably Easy)


hoopplaya4

Recommended Posts

I'm having some difficulty with the Syntax on this statement:

 

<?php 
$data = mysql_query("UPDATE profilePics SET def='0' WHERE filename= (SELECT filename FROM profilePics WHERE usrID='$usrID' AND def='1'")) or die(mysql_error());

 

I get the following error:

 

Parse error: syntax error, unexpected ')'

 

What am I doing wrong here?  Thanks!

Link to comment
Share on other sites

$data = mysql_query("UPDATE profilePics SET def='0' WHERE filename= (SELECT filename FROM profilePics WHERE usrID='$usrID' AND def='1'")) or die(mysql_error();

All you have to do is count.  The "or die" part never gets passed to mysql_query().

Link to comment
Share on other sites

Thanks for the reply Ober, I tried your example verbatim, and I'm still getting the same syntax error.  So this time, I tried removing the or die altogether:

 

<?php
$data = mysql_query("UPDATE profilePics SET def='0' WHERE filename= (SELECT filename FROM profilePics WHERE usrID='$usrID' AND def='1'"));

And with this one, I am still getting the same error as well.  :-\

 

Link to comment
Share on other sites

Thanks for the help mrMarcus.  This has certainly cured my syntax issue!!

 

But, I'm now getting the following MySQL error:

 

You can't specify target table 'profilePics' for update in FROM clause

 

I'm not sure what this means off-hand.  If anyone does, that'd be great.  Otherwise, I'm gonna see what I can find.  Thanks again!

Link to comment
Share on other sites

basically it means you can't do a subquery selecting data from the same table you are updating.  To get around it, you have to create a temp table and/or temp vars.  I don't personally know how to write that for you; that's beyond my sql knowledge.  I'll move this to the sql forum where you'll get a more specific answer.

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.