Page 1 of 1

Warning: mysql_fetch_array() problems

Posted: Wed Oct 29, 2008 2:29 am
by ThuggLife
Hi, I have this problem with retrieving data from my database, any help would greatly appreciated.
here is a snippet of code, the error is in the mysql_fetch_array() function. I can connect to my databse fine, but cant retrieve data.

Code: Select all

<?php
    
//connecting to mySQL database
    $dbhost = 'localhost';
    $dbuser = 'XXXX';
    $dbpass = 'XXXX';
    $dbname = 'XXXX';
 
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die  ('Error connecting to mysql');
 
    mysql_select_db($dbname);
//
//get form variables and use them for querry
    
    $query = "SELECT * FROM XUSERS";
    $result = mysql_query($query);
//
 
    while ($row = mysql_fetch_array($result)) 
{
    echo $row['id'];
}
?>
I have looked all over the net for answers, and it seems most of the time this error is caused by a query that dosn't work. However, I have copy and pasted the exact query into my database and it works fine, but when I try it with the mysql_fetch_array($querry) it says... Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/xanatosm/public_html/dataBaseInfo.php on line 37.

please help, Im going crazzy. :P

Re: Warning: mysql_fetch_array() problems

Posted: Wed Oct 29, 2008 2:54 am
by ThuggLife
Found out that there was a little typo in my database name. The reason I thought I was connected is because my code used to spit out an error in the line

Code: Select all

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die  ('Error connecting to mysql');
but after editing my the code it stopped saying 'Error connecting to mysql', so I assumed it connected and the problem was with the mysql_fetch_array() function. I was wrong.

From google research on this topic it seems to be a pretty common problem. I found the solution by viewing a post on a different forum by someone having the same problem (it turned out to be a typo in the database or host name).

I'll leave this here to return the favor. :)