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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post

    I get this often, dunno why...

    Error:
    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a9012858/public_html/scripts/getReview.php  on line 14
    PHP:
    PHP Code:
    <?php
    include "connect.php";

    //Connect to database
    mysql_select_db($dbname$con);

    //Get data from database for current user
    $id $_GET['id'];
    $result mysql_query("SELECT * FROM comments WHERE id=$id");
    /*if (!result) {
        echo "No reviews yet!";
    }*/

    while ($row mysql_fetch_array($result)) {
    //Variables to echo out data
    $name=$row['name'];
    $message=$row['message'];
    $date=$row['date'];
    $id=$row['id'];

    //Display results
    echo 
    "<div class=\"comment\">
        <div class=\"commentDiv\">Posted by $name</div>
        <div class=\"message\">$message</div>
        <div class=\"commentDiv\">Posted on $date</div>
    </div>"
    ;
    }
    ?>
    I don't what is wrong with it....

  • #2
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    It means that the result resource you're trying to pull a row from isn't actually a result.

    Change this:

    PHP Code:
    $result mysql_query("SELECT * FROM comments WHERE id=$id"); 
    To this:

    PHP Code:
    $result mysql_query("SELECT * FROM comments WHERE id=$id") or die(mysql_error()); 
    and rerun your code. That will tell you if your query failed and why.

  • Users who have thanked bacterozoid for this post:

    martynball (03-02-2010)

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    Cheers

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    It's also a good idea to wrap all of the values you use in single quotes for things like $id in your example
    $result = mysql_query("SELECT * FROM comments WHERE id='$id'");
    This means if your id accidentally has a string instead of a numeric value it's not going to throw an error about your query, it just won't return a result
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

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