SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    supplied argument not valid

    Hi,

    I don't see anything wrong but i keep getting this message

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/badede/public_html/home.php on line

    The code

    Code PHP:
    $query2 = "SELECT photo_id FROM listing_photo WHERE (listing_id = ' ".$rows['id']. " ' AND key = 1) ";
    $result2 = mysql_query($query2);
    $rows2 = mysql_fetch_array($result2);
    Last edited by runrunforest; Dec 15, 2008 at 22:45.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i don't do php but i think that's a php error, not a mysql error

    the first part of the string is --

    $query2 = "SELECT photo_id FROM listing_photo WHERE (listing_id = "

    then a single quote follows, which i believe is a php error

    try it without the single quotes

    you shouldn't put quotes around numeric values anyway

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict wibble wobble's Avatar
    Join Date
    Dec 2008
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have:
    listing_id = ' ".$rows['id']. " '
    That should be
    listing_id = ".$rows['id']. "
    without the single quote and without the space between the single/double quotes.
    Find freelance jobs from all the major sites in one place:
    on twitter / on the web / twitter rss feed

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    When you get that error, it means the query hasn't been executed correctly and produced an error.
    To see what's wrong with a query, you should do the following:
    1) add or die('Invalid query: ' . mysql_error()); after the mysql_query
    2) echo the query you're executing, so you can control if it's ok

    PHP Code:
    $query2 "SELECT photo_id FROM listing_photo WHERE (listing_id = ' ".$rows['id']. " ' AND key = 1) ";
    echo 
    "<br />query2 : $query2 <br />";
    $result2 mysql_query($query2) or die('Invalid query: ' mysql_error());
    $rows2 mysql_fetch_array($result2); 
    This way, if you still don't know what's wrong, you can give us some additional information

  5. #5
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    To see what's wrong with a query, you should do the following:
    1) add or die('Invalid query: ' . mysql_error()); after the mysql_query
    2) echo the query you're executing, so you can control if it's ok
    I actually tried most of sql debugging before the post.

    Good news that the problem solved. The AND key = 1 was the culprit, it's supposed to be `key`= 1 , I put back quote on the word "key"

    Anyway, does someone know where I can find list of characters need to be back-quote in mysql ?

  6. #6
    SitePoint Addict wibble wobble's Avatar
    Join Date
    Dec 2008
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by runrunforest View Post
    does someone know where I can find list of characters need to be back-quote in mysql ?
    The full list here: http://dev.mysql.com/doc/refman/5.1/...ved-words.html

    Edit: Thats for version 5.1 anyway.
    Find freelance jobs from all the major sites in one place:
    on twitter / on the web / twitter rss feed

  7. #7
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks mate.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •