hoopplaya4 Posted April 17, 2009 Share Posted April 17, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/154517-solved-syntax-issue-probably-easy/ Share on other sites More sharing options...
ober Posted April 17, 2009 Share Posted April 17, 2009 $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(). Quote Link to comment https://forums.phpfreaks.com/topic/154517-solved-syntax-issue-probably-easy/#findComment-812419 Share on other sites More sharing options...
hoopplaya4 Posted April 17, 2009 Author Share Posted April 17, 2009 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. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/154517-solved-syntax-issue-probably-easy/#findComment-812445 Share on other sites More sharing options...
ober Posted April 17, 2009 Share Posted April 17, 2009 What version of MySQL? MySQL 4 doesn't support subqueries, which is what you are trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/154517-solved-syntax-issue-probably-easy/#findComment-812463 Share on other sites More sharing options...
mrMarcus Posted April 17, 2009 Share Posted April 17, 2009 <?php $data = mysql_query("UPDATE profilePics SET def='0' WHERE filename= (SELECT filename FROM profilePics WHERE usrID='$usrID' AND def='1')"); move your double-quote outside the inside bracket ')"); Quote Link to comment https://forums.phpfreaks.com/topic/154517-solved-syntax-issue-probably-easy/#findComment-812464 Share on other sites More sharing options...
ober Posted April 17, 2009 Share Posted April 17, 2009 Damn... missed that. Good catch. Quote Link to comment https://forums.phpfreaks.com/topic/154517-solved-syntax-issue-probably-easy/#findComment-812471 Share on other sites More sharing options...
mrMarcus Posted April 17, 2009 Share Posted April 17, 2009 ^gracias amigo. should work now. Quote Link to comment https://forums.phpfreaks.com/topic/154517-solved-syntax-issue-probably-easy/#findComment-812486 Share on other sites More sharing options...
hoopplaya4 Posted April 17, 2009 Author Share Posted April 17, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/154517-solved-syntax-issue-probably-easy/#findComment-812521 Share on other sites More sharing options...
.josh Posted April 17, 2009 Share Posted April 17, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/154517-solved-syntax-issue-probably-easy/#findComment-812528 Share on other sites More sharing options...
hoopplaya4 Posted April 17, 2009 Author Share Posted April 17, 2009 Got it figured out! Here's the statement I used: UPDATE profilePics SET def = '0' WHERE filename = ( SELECT filename FROM ( SELECT * FROM profilePics ) AS temp WHERE usrID = '25' AND def = '1' ) Thanks everyone. Quote Link to comment https://forums.phpfreaks.com/topic/154517-solved-syntax-issue-probably-easy/#findComment-812562 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.