Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    122
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

    WRONG SECTION. DELETE PLEASE.






    I have this code:

    PHP Code:
    $number1 "1";
    $number2 "1";
    $seven rand($number2$number1);
    $con mysql_connect("my host","username","password");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("my_db"$con);

    $result mysql_query("SELECT * FROM images WHERE $seven = $id");

    while(
    $result mysql_fetch_array($result))
      {
    $title $result['Title'];

    echo 
    $title;

      } 
    Got this error on page: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web258/b2582/ipg.crowngaming/pictures.php on line 240

    Here's line 240:

    PHP Code:
    while($result mysql_fetch_array($result)) 
    Last edited by Xaqa; 10-26-2011 at 12:28 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    This is almost surely wrong:
    Code:
    $result = mysql_query("SELECT * FROM images WHERE $seven = $id");
    $seven and $id are *BOTH* PHP variables. Or, rather, they should be.

    If $seven is not initialized, then your query becomes
    Code:
         SELECT * FROM images WHERE  = 777
    (or something like that). So you have a SQL error, and so you are *NOT* getting a valid $result.

    You should do:
    Code:
    $result = mysql_query("SELECT * FROM images WHERE $seven = $id")
              or die("<hr>error in SQL query: " . mysql_error() . "<hr>");
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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