View Full Version : mysql_fetch row error?

08-21-2005, 09:28 AM
echo "This is a test";
echo "<br>I am gonna try connecting to the database :D";

$db = mysql_connect("localhost","","");
$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?

08-21-2005, 12:05 PM
Have you put in anything to be fetched yet?

08-21-2005, 12:54 PM
add "or die(mysql_error()) to your db connect adn query" it will tell you what the mysql error is.

08-21-2005, 04:29 PM
$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.

08-21-2005, 06:43 PM
I think this line is giving the error:

$result = mysql_query("SELECT * FROM hymnTables",$db);
The $db is not the database.
Get the exact name of your database and change to:

$db = "database_name";
$result = mysql_query("SELECT * FROM $db.hymnTables");
Use this instead to get your database's name:

$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";

Kid Charming
08-23-2005, 03:14 AM
$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.