advice on this error

Discussion in 'PHP' started by Funk-woo10, Dec 12, 2007.

  1. #1
    Hi

    Can any1 tell me what this error means ?

    Thanks.

    Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/pictures/public_html/functions.php on line 83
    PHP:
     
    Funk-woo10, Dec 12, 2007 IP
  2. danzor

    danzor Peon

    Messages:
    208
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your query was wrong. Check the syntax, column names etc.
     
    danzor, Dec 12, 2007 IP
  3. itsme

    itsme Well-Known Member

    Messages:
    1,232
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    180
    #3
    also double check your spelling on the result variable.
     
    itsme, Dec 12, 2007 IP
  4. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #4
    spelling ?
     
    Funk-woo10, Dec 12, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    Post your code if you have done the above and need further help.
     
    nico_swd, Dec 12, 2007 IP
  6. itsme

    itsme Well-Known Member

    Messages:
    1,232
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    180
    #6
    Yes, sometimes you can have a typo and not notice it right away... for example:

    if your query result is $result but you typed $resut by mistake... you'll get that error.
     
    itsme, Dec 12, 2007 IP
  7. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It might not even be the spelling or an incorrect query

    - Make sure you aren't passing the actual query string into mysql_fetch_object(), it needs to be a result
    - Make sure you are passing the right variable

    nico_swd is right though. If you want real clarification post the code that caused the error.
     
    tonybogs, Dec 12, 2007 IP
  8. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #8
    ok , here is the code


    <?
    
    $sql="select * from members,photos,ratings where members.username=photos.username and photos.photosid=ratings.photosid and numvotes>0 and gender='F'  and approved='Y'  and active=1 order by avgrating desc LIMIT 5";
       $res=mysql_query($sql) OR die(mysql_error());
       $rows = 0;
       ?>
    
       <?php
    
       while($obj=mysql_fetch_object($res))
       {
    
    
       	if($obj->url=="")
       	{
       		$img="<a href='http://www.***.com/index.php?&username=$obj->username&phid=$obj->photosid''><img border=0 width=50 height=50 src='../pics/$obj->filename'></a>";
       	}
       	else
       	{
       		$img="<a target='_blank' href='$obj->url'><img  border=0 width=100 height=100 src='$obj->url'></a>";
       	}
    
       	$id=$obj->photosid;
       	$username=$obj->username;
       	print $img;
    
       	?>
           	<br /><a href="http://www.***.com/index.php?cmd=20&username=<? print $username; ?>">View <? print $username; ?>'s profile</a>
           <?php
    
    
    
       }
    
       ?>
    PHP:
     
    Funk-woo10, Dec 13, 2007 IP
  9. arnek

    arnek Active Member

    Messages:
    134
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #9
    what happens if you run the sql statement straight on the server ?(not from the program)

    Just to confirm that your query is correct.
     
    arnek, Dec 13, 2007 IP
  10. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #10
    It works fine, its when I add more sql statements its as if they 'colide' with each other, i.e to much sql.
     
    Funk-woo10, Dec 13, 2007 IP
  11. itsme

    itsme Well-Known Member

    Messages:
    1,232
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    180
    #11
    try surrounding table and field names with the ` character

    `like`.`this`

    sometimes that takes care of the problem... but you should focus on the SQL... that's usually the problem. I doubt that it's a bummed PHP/MYSQL install. You could try it on another server if you think the software might be the problem.
     
    itsme, Dec 13, 2007 IP