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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Dec 2004
    Location
    Jamaica
    Posts
    592
    Thanks
    2
    Thanked 0 Times in 0 Posts

    mysql_fetch row error?

    PHP Code:
    <?php
    echo "This is a test";
    echo 
    "<br>I am gonna try connecting to the database :D";

    $db mysql_connect("localhost","","");
    mysql_select_db("digihymnal",$db);
    $result mysql_query("SELECT * FROM hymnTables",$db);

    this line: while($rec mysql_fetch_row($result))
      {
      
      }


    ?>
    Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in ....
    Whats wrong?
    I'm gonna find a way to download the internet if its the last thing I do...
    Prepare to bow down to me (or my grave) and call me almighty when the algorithm is finished

  • #2
    New Coder
    Join Date
    Jul 2005
    Location
    Perth, Australia. Age: 13
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have you put in anything to be fetched yet?
    Last edited by e-Raser; 08-21-2005 at 02:05 PM.
    I lost my signature, have you seen it?
    I have the power to erase you...

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    add "or die(mysql_error()) to your db connect adn query" it will tell you what the mysql error is.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    $result != resource. Simple as that, no value is being returned from your mysql query. This could be due to no database connection, no database selected, or invalid query. Ensure your database location & port, username, and password, as well as your database name, and table name are accurate. I'm assuming they are blanked off for your posting here for your username and password. Since your error isn't triggered, I'd assume as well that the problem is based soley on the call to the database table. You don't really need your connection in there btw, as its already been opened and will work fine for the remainder of the script run. hymnTables may be incorrectly stated, especially since mysql has a habit of lowercasing all table names. Try altering your query to select on 'hymntables'. Presto. Hopefully this will fix your problem, but mysql I find is rarely case sensitive, so we'll have to see.
    Last edited by Fou-Lu; 08-21-2005 at 03:32 PM.

  • #5
    Regular Coder
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    I think this line is giving the error:
    PHP Code:
    $result mysql_query("SELECT * FROM hymnTables",$db); 
    The $db is not the database.
    Get the exact name of your database and change to:
    PHP Code:
    $db "database_name";
    $result mysql_query("SELECT * FROM $db.hymnTables"); 
    Use this instead to get your database's name:
    PHP Code:
    <?php
    $link 
    mysql_connect('localhost''mysql_user''mysql_password');
    $db_list mysql_list_dbs($link);

    while (
    $row mysql_fetch_object($db_list)) {
        echo 
    $row->Database "\n";
    }
    ?>

  • #6
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $db's not supposed to be the database; it's the link identifier returned from mysql_connect(). Jaywhy13's usage of the mysql_connect(), mysql_select_db(), and mysql_query() functions is correct.


  •  

    Posting Permissions

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