Mysql fetch array?

salukigirl

New Member
Messages
78
Reaction score
0
Points
0
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/star/public_html/bunnygame/forums/loggedinas.php on line 7

I get that in every code of mine that has that function. Does my version of PHP not support it?
I need to use that function...
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
That means you're either not connected to the database OR you're retrieving an empty query.
 

genki

New Member
Messages
7
Reaction score
0
Points
0
It's most likely not a version issue. Most likely:

1. Your script has not connected to the database in order to run the query
or
2. Your script connects to the database but there are no records (no data) that matches the query. In other words, you got an "empty" result set.

To test #1, run the following code BEFORE any other code in your PHP script. If it's working okay, it should display "resource #14" or something like that.

# Purpose: Establish a connection to the database
#
$dbname = 'your_database_name_here';
$dbhost = 'localhost';
$dbusername = 'your_username_here';
$dbpassword = 'your_password_here';
#
$dbconnection = @mysql_connect($dbhost, $dbusername, $dbpassword);
if ($dbname != '' && !@mysql_select_db($dbname)) {
echo 'I could NOT connect to the database! Check the username, password, etc.';
} else {
echo 'I connected. The connection is: ' . $dbconnection;
}


To test #2, enter your query directly into phpMyAdmin and see what it tells you. It will say "0 records returned" or it will give you an error message. 0 records means the query was acceptable but no data matched your search. If you get an error, it means your query is broken and ya gots some fixin' to do!

Does that help? (If yes, please click my reputation checkmark :)
 
Last edited:

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,818
Reaction score
163
Points
63
not my thread, but having the same problem, I did the first check and It says it connected. but my script still displays the error
 

genki

New Member
Messages
7
Reaction score
0
Points
0
If your PHP script connects to the server, the problem is with your query-- either the query is invalid or there is no data that matches what you are asking for.

To find out if the syntax of your query is okay, You can ask PHP to display errors by doing this:

# Purpose: Establish a connection to the database
#
$dbname = 'your_database_name_here';
$dbhost = 'localhost';
$dbusername = 'your_username_here';
$dbpassword = 'your_password_here';
#
$dbconnection = @mysql_connect($dbhost, $dbusername, $dbpassword);
if ($dbname != '' && !@mysql_select_db($dbname)) {
echo 'I could NOT connect to the database! Check the username, password, etc.';
} else {
echo 'I connected. The connection is: ' . $dbconnection;
}

// execute a search
mysql_query("SELECT * FROM nonexistenttable", $dbconnection);
// display the error number and error text
echo mysql_errno($link) . " : " . mysql_error($link);

BTW, the online PHP manual is here: http://www.php.net/manual/en/
 
Last edited:
Top