Chevy Posted December 10, 2007 Share Posted December 10, 2007 Okay, so I am making a friends script, and this is the query giving me hell $friend_select = mysql_query("SELECT * FROM `friends` WHERE (`from`='$global[username]' AND `accepted`='Yes') OR (`to`='$global[username]' AND `accepted`='Yes') "); Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/ Share on other sites More sharing options...
Chevy Posted December 10, 2007 Author Share Posted December 10, 2007 This is kind of urgent :/ Sorry to rush things. Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411402 Share on other sites More sharing options...
roopurt18 Posted December 10, 2007 Share Posted December 10, 2007 Change your code to give you more meaningful information for the purposes of debugging: $friend_select = mysql_query("SELECT * FROM `friends` WHERE (`from`='$global[username]' AND `accepted`='Yes') OR (`to`='$global[username]' AND `accepted`='Yes') ") or die('Error: ' . mysql_error()); This is kind of urgent :/ Your problems are no more urgent than anyone else seeking free help. Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411427 Share on other sites More sharing options...
Chevy Posted December 10, 2007 Author Share Posted December 10, 2007 Your problems are no more urgent than anyone else seeking free help. Heh true there I get this error, which I still have no clue what is wrong? #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql_query("SELECT * FROM `friends` WHERE `from`='Chevy' AND `accepted`='Yes' Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411434 Share on other sites More sharing options...
roopurt18 Posted December 10, 2007 Share Posted December 10, 2007 Try this and paste the output: $friend_select = "SELECT * FROM `friends` WHERE (`from`='$global[username]' AND `accepted`='Yes') OR (`to`='$global[username]' AND `accepted`='Yes') "; echo '<pre style="text-align: left;">' . print_r($friend_select, true) . '</pre>'; $q = mysql_query($friend_select) or die('Error: ' . $friend_select . ' ## ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411444 Share on other sites More sharing options...
Chevy Posted December 10, 2007 Author Share Posted December 10, 2007 This is what it outputted SELECT * FROM `friends` WHERE (`from`='Chevy' AND `accepted`='Yes') OR (`to`='Chevy' AND `accepted`='Yes') Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/public_html/friends.php on line 83 Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411445 Share on other sites More sharing options...
teng84 Posted December 10, 2007 Share Posted December 10, 2007 $friend_select = "SELECT * FROM `friends` WHERE `from`='".$global['username']."' AND `accepted`='Yes' OR `to`='".$global['username']."' AND `accepted`='Yes'"; $q = mysql_query($friend_select) or die('Error: ' . $friend_select . ' ## ' . mysql_error()); try Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411459 Share on other sites More sharing options...
roopurt18 Posted December 10, 2007 Share Posted December 10, 2007 teng, removing the parentheses is just going to screw up the query logic. The query that was run from the code I gave him looks correct. @Chevy, paste your code from the moment you create the query until you try to call mysql_fetch_assoc(). If you left the or die() in there and it didn't trigger, then the query was syntactically correct and the problem must be elsewhere. Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411461 Share on other sites More sharing options...
Chevy Posted December 10, 2007 Author Share Posted December 10, 2007 $friend_select = mysql_query("SELECT * FROM `friends` WHERE (`from`='$global[username]' AND `accepted`='Yes') OR (`to`='$global[username]' AND `accepted`='Yes')"); $requests_select = mysql_query("SELECT * FROM `friends` WHERE `to`='$global[username]' AND `accepted`='No'"); mysql_query("UPDATE `users` SET `friendalert`='0' WHERE `username`='$global[username]'"); //Just HTML stuff till line 81 if (mysql_num_rows($friend_select) == "0"){ echo '<font color="red"><b>You do not have any friends at the moment </b></font>'; } else { while ($yourfriends = mysql_fetch_array($friends_select)){ That all it looks like 0_o, this is really weird. Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411463 Share on other sites More sharing options...
teng84 Posted December 10, 2007 Share Posted December 10, 2007 teng, removing the parentheses is just going to screw up the query logic. The query that was run from the code I gave him looks correct. @Chevy, paste your code from the moment you create the query until you try to call mysql_fetch_assoc(). If you left the or die() in there and it didn't trigger, then the query was syntactically correct and the problem must be elsewhere. sorry my bad how come i don't see that lol any way ignore my post Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411465 Share on other sites More sharing options...
Chevy Posted December 10, 2007 Author Share Posted December 10, 2007 Heh now it wants to give me an error... Unknown column 'Chevy' in 'where clause' ...oh really...? What is that telling me exactly? xD Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411467 Share on other sites More sharing options...
teng84 Posted December 10, 2007 Share Posted December 10, 2007 i dont know if this is your original code see this line while ($yourfriends = mysql_fetch_array($friends_select)){ you don't have $friends_select but you have $friend_select Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411468 Share on other sites More sharing options...
roopurt18 Posted December 10, 2007 Share Posted December 10, 2007 You changed your variable name in the mysql_fetch_assoc() line: $friend_select ==> $friends_select Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411470 Share on other sites More sharing options...
Chevy Posted December 10, 2007 Author Share Posted December 10, 2007 Wow... I should uh, never show my face to the world again. That was the problem. Thanks. I am still shocked at how stupid I was. Sorry guys. Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411471 Share on other sites More sharing options...
roopurt18 Posted December 10, 2007 Share Posted December 10, 2007 Those kinds of mistakes don't happen any less with time, but you do get better at finding them. The simple thing to do here would have been echo your $friends_select right before the mysql_fetch_assoc() call; note that when echo'ing variables for debugging it helps to copy and paste the variable rather than retyping it as you may retype it correctly. I once lost a half an hour because of incorrect capitalization on a 'c' in a variable name, 'c' and 'C' can look so similar. Another [uncommon] but very, very tricky error, is when someone accidentally places a semicolon after the closing parenthesis of a conditional or loop. Quote Link to comment https://forums.phpfreaks.com/topic/81069-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql/#findComment-411474 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.