Supplied argument is not a valid MySQL result resource.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kalyanip14
    New Member
    • Feb 2009
    • 3

    Supplied argument is not a valid MySQL result resource.

    Hi I am new to Php.I am trying to read My sql database data from table to php.

    I am getting this warning

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

    and my code is
    [code=php]
    <?php

    $con = mysql_connect(" localhost","san dman","sandcast le");

    if (!$con)

    {

    die('Could not connect: ' . mysql_error());

    }

    print "Connected to MySQL<br>";



    mysql_select_db ("sandbox", $con);



    $result = mysql_query("SE LECT parcel,location from accessor");



    echo "<table border='1'>

    <tr>

    <th>Parcel</th>

    <th>Location</th>

    </tr>";
    while($row = mysql_fetch_arr ay($result))

    {

    echo "<tr>";

    echo "<td>" . $row['parcel'] . "</td>";

    echo "<td>" . $row['location'] . "</td>";



    echo "</tr>";

    }


    echo "</table>";



    mysql_close($co n);

    ?>
    [/code]
    plz let me know where I am doing wrong
    Last edited by Atli; Feb 5 '09, 08:17 PM. Reason: Added [code] tags.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I guess the query failed and thus returned false (which is not a valid resource).

    Comment

    • kalyanip14
      New Member
      • Feb 2009
      • 3

      #3
      Hi Dormilich

      Thanks for you reply.But resource are correct..

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        Originally posted by kalyanip14
        Thanks for you reply.But resource are correct..
        Apparently, they are not.
        PHP warnings do not lie, and this one is telling you that the resource is not valid.

        You should always make sure of this yourself before you try to use the resource returned by a function.
        The usual way to do that with MySQL queries is to do:
        [code=php]$result = mysql_query("yo ur query here") or die(mysql_error ());[/code]
        This prints the error you SQL is generating and stops the code from executing any further, if the SQL query fails.
        If the SQL query is successful, it moves on the the next line of code.

        If you want to handle this more gracefully, you can simply check the $result of the query before it is used. If it is FALSE, your query failed.

        Comment

        • kalyanip14
          New Member
          • Feb 2009
          • 3

          #5
          Hi

          I sloved it thanks for your help

          Comment

          Working...