Results 1 to 4 of 4

Thread: supplied argument is not a valid mysql result resource, help

  1. #1
    Join Date
    Nov 2005
    Posts
    403

    supplied argument is not a valid mysql result resource, help

    I have written a code running which returns with an error "supplied argument is not a valid mysql result resource" for:

    Code:
    <?php
    while($row = mysql_fetch_array($result))
    {
    ?>
    Can anyone help me out what is wrong here? Thank you
    Don't talk unless you can improve the silence.

  2. #2
    Join Date
    Dec 2007
    Posts
    1,599

    Re: supplied argument is not a valid mysql result resource, help

    Your SQL query is failing. Use the or die mysql_error();. This will display the problem.
    Code:
    <? 
    $sql = "SELECT * FROM `mytable` WHERE `id` = '1'"; 
    
    db_connect();//connecting mysql db function i wrote 
    
    $result = mysql_query($sql) or die(mysql_error()); 
    
    while($row = mysql_fetch_array($result)){ 
    
     // do some thing here 
    
    }  
    
    mysql_close(db_connect()); 
    ?>

  3. #3
    Join Date
    Dec 2007
    Posts
    1,547

    Re: supplied argument is not a valid mysql result resource, help

    This error message indicates that an error occurred in the call to mysql_query, which is indicated by a return of FALSE. FALSE is not a valid resource identifier, and so you get the error shown. When mysql_query returns FALSE, you should echo the error message indicated by mysql_error() to find out what the real error was.

  4. #4
    Join Date
    Jun 2006
    Posts
    623

    Re: supplied argument is not a valid mysql result resource, help

    It is possible that the query failed, or that you failed to connect to the database server. Checking for these potential problems and gracefully handling them should be the way to go.

    Incidentally, use mysql_num_rows() not mysql_numrows() as the latter is deprecated.

    Using "values" as a table name could create problems since values is a mysql keyword. Try changing the table name and see if it starts working.

Similar Threads

  1. Replies: 8
    Last Post: 08-05-2012, 12:46 PM
  2. Replies: 4
    Last Post: 24-04-2012, 07:53 AM
  3. How to match MySQL result from keywords?
    By Utpalini in forum Windows Software
    Replies: 5
    Last Post: 30-08-2011, 09:28 AM
  4. Replies: 3
    Last Post: 07-11-2009, 09:36 PM
  5. How to combine 3 result rows in mysql
    By HAKAN in forum Software Development
    Replies: 3
    Last Post: 20-05-2009, 10:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,285,408.86981 seconds with 16 queries