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
https://forums.phpfreaks.com/topic/154517-solved-syntax-issue-probably-easy/
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().

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.  :-\

 

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!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.