Jump to content

[SOLVED] Warning: mysql_fetch_array(): supplied argument is not a valid MySQL


Recommended Posts

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?

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.  ;)

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'

 

 

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());

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

$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

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.

$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.

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

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.

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.