Help with mysql error Please

Discussion in 'PHP' started by learnwebsitedesigncom, Apr 19, 2011.

  1. #1
    Hi, I am getting this error message and would like some help figuring out where I'm going wrong. The error message that I'm getting is this:

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

    The lines of code that it is referring to are these:

     $read = "
      SELECT * freewebsitehostingreviews_com_reviews WHERE host='$host' && display_post='YES'
     ";
     $result = mysql_query($read);
     while($row = mysql_fetch_array($result))
      {
       echo '<p><br />' . $row['post_date'] . '<br />' . $row['reviews'] . '</p>';
      }
    Code (markup):
     
    learnwebsitedesigncom, Apr 19, 2011 IP
  2. littlejohn199

    littlejohn199 Peon

    Messages:
    42
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You got this error is because the $result being returned is not a mysql result set. It means that there is something wrong with your "SELECT" statement or mysql connection.

    Add this to your code

    $result = mysql_query($read) or die(mysql_error());

    die(mysql_error()) will tell you more about the error that you got.

    Little John
     
    littlejohn199, Apr 19, 2011 IP
  3. phppro9x

    phppro9x Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Syntax error
    Edit:

     
    phppro9x, Apr 19, 2011 IP
  4. learnwebsitedesigncom

    learnwebsitedesigncom Active Member

    Messages:
    264
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Nevermind, I left the "FROM" out of the sql statement :|

    But thanks for the help.
     
    learnwebsitedesigncom, Apr 19, 2011 IP
  5. shuhail

    shuhail Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    $read = "SELECT * FROM freewebsitehostingreviews_com_reviews WHERE host='$host' && display_post='YES'";
    $result = mysql_query($read);
     while($row = mysql_fetch_array($result))
      {
    $pdate= $row['post_date'];
    $review=$row['reviews'];
       echo "<p><br />" . $pdate . "<br />" . $review . "</p>";
      }
    
    PHP:
     
    shuhail, Apr 19, 2011 IP
  6. karmaa

    karmaa Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    $result = mysql_query($read) ..
    mysql_fetch_array(): supplied argument is not a valid because the data in the $result is not an array. Try echo $result and see if all the fields are displayed or not
     
    karmaa, Apr 20, 2011 IP
  7. ap2010

    ap2010 Guest

    Messages:
    41
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You have to fix your query first, you're missing the "FROM" keyword and you must also use the ANSI-SQL standard "AND" operator, not the PHP "&&" (although mysql will happily accpet it):

     $read = "
    SELECT * FROM freewebsitehostingreviews_com_reviews WHERE host='$host' AND display_post='YES'
    ";
    PHP:
    It is also a good practice to use mysql_error() when your query fails for some reason:

    $result = mysql_query($read) or die(mysql_error());
    PHP:
     
    ap2010, Apr 20, 2011 IP