PDA

View Full Version : mysql_result(): supplied argument is not a valid MySQL


Len Whistler
02-14-2008, 03:38 AM
I just switched my host and I get this error when I try and connect to the MySQL database:

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

All database usernames, passwords, and database name are correct in my files and I can't figure out what is happening. I can duplicate the error on my home computer by entering the wrong database name in my database_connect php file. I have contacted support but haven't heard back from them. To view the error go to www.stubby.ca

CFMaBiSmAd
02-14-2008, 04:16 AM
The error means the mysql_query() failed and the code blindly executed a mysql_result() statement when there was no result resource.

Post your code to get the quickest solution.

Len Whistler
02-14-2008, 07:13 AM
This is the db_connect.php file it works on my home computer and my old host. It doesn't work with the new host.



db_connect.php
<?php
define ('DB_USER', 'a4944448_lenny');
define ('DB_PASSWORD', 'canon712');
define ('DB_HOST', 'localhost');
define ('DB_NAME', 'a4944448_stubby');

$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die(mysql_error());
mysql_select_db (DB_NAME);
?>

abduraooft
02-14-2008, 07:24 AM
I don't think the above posted code is causing the error!
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/a4983668/public_html/index.php on line 19
The error might be with your mysql_query(), change it as
mysql_query(".......") or die(mysql_error());

Also note that it is your responsibility to die() if necessary.

Len Whistler
02-14-2008, 07:39 AM
Thanks abduraooft....... In the index.php file I have the code as mysql_query(".......") and it works on the old host and my home computer.

The problem seems to be the database name. I can duplicate the error by entering the wrong DB name on my home computer and when the correct name is entered it works. But my new host doesn't recognize the correct name at all as below:

define ('DB_NAME', 'a4944448_stubby');

abduraooft
02-14-2008, 08:07 AM
If your argument is right, then
mysql_select_db (DB_NAME,$dbc) or die(mysql_error()); should say Unknown database 'a4944448_stubby' .

Len Whistler
02-14-2008, 08:18 AM
Ok thanks abduraooft .... mysql_select_db (DB_NAME,$dbc) or die(mysql_error()); gives me a better error meassage:

Access denied for user 'a4983668_lenny'@'localhost' to database 'a4983668_stubby'

Must be the permissions are not set properly.

abduraooft
02-14-2008, 08:23 AM
Len Whistler, I hope the password posted above is not real, otherwise change it immediately!

Len Whistler
02-14-2008, 08:30 AM
Len Whistler, I hope the password posted above is not real, otherwise change it immediately!


No I changed some numbers in the post. You can see the current error message at www.stubby.ca. It's getting late so I will work on this tomorrow.

Len Whistler
02-14-2008, 08:47 AM
Ok....I got it going by using the Cpanel's username and password, instead of the new user I created in MySQL. Thanks abduraooft and CFMaBiSmAd for your help.