Page 1 of 1

not a valid MySQL result resource

Posted: Fri Apr 17, 2009 7:27 pm
by mikes1471
Hi

I get this error message:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/redlemons.com/httpdocs/new/albums.php on line 18

and despite this message I cant see where the problem is in my code:

Code: Select all

<table cellpadding='7' width='100%'>
    <tr>
        <td>
        <font face='arial' size='4'>
        My Albums<p>
        <font size='2'>
        ";
        $id = $_SESSION['id'];
        $album = mysql_query("SELECT * FROM albums WHERE userid='$id'");
        
        echo "<table width='50%'>";
        while ($row = mysql_fetch_assoc($album))
        {
        echo "
        <tr>
            <td>
            <img src='store/".$row['cover']."' width='100' height='100'>
            </td>
            <td>
            <b>".$row['name']."</b><br>
            ".$row['description']."
            </td>
        </tr>
        ";
        }
        echo "</table>
I wonder if someone could help me with this as im stuck!

Re: not a valid MySQL result resource

Posted: Fri Apr 17, 2009 11:44 pm
by califdon
There may be no problem with your code. That error message means that your query didn't return a valid result dataset. That is often not a code problem, but a data problem. You will never know if you don't trap the error MySQL returns to you. Change your query code to this:

Code: Select all

$sql = "SELECT * FROM albums WHERE userid='$id'";
$album = mysql_query($sql) or die(mysql_error() . "<br/> $sql");
That is likely to return all the information you need to determine the problem and its solution.