Page 1 of 1

[RESOLVED] WARNING: mysql_fetch_row()

Posted: Sat Dec 02, 2006 12:37 pm
by screwcork
Hi there! I'm rather new at PHP. Currently i'm just playing around with code trying to make it do what i actually want it to!

then i stumbled upon a problem....

Code: Select all

$db_user = "username";		
$db_pass = "database";		
$db_host = "localhost";		
$db_name = "my_database";

$db = mysql_connect($db_host,$db_user,$db_pass);

mysql_select_db($db_name);

$query = "SELCT * FROM users";
$result = mysql_query($query);
while ($record = mysql_fetch_row($result)) {
	for ($i=0; $i<count($record); $i++) {
		echo $record[$i]."<br>";
	}
	echo "<br>";
}
The script above won't work propperly. It's intended to fetch the info from the database and simply display it in the browser. let me just specify that the row "users" do exist in the database i try to connect to. And ofcourse in my own copy of the code above i have entered username, password and so on in their own place respectively...

What happens when i upload the script and run it is that I get this error message:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home2/prexserv/public_html/learning_php/lesson6/06_03_database.php on line 14

I understand that something is wrong with the " while ($record = mysql_fetch_row($result)) " I just don't know why!

What i'm wondering here is if the script is wrong or if it is a connection probem... (i am currently using PHP/mySQL scripts on the server so the setup on the server itself is corect as far as i know)

-Chris

Posted: Sat Dec 02, 2006 1:03 pm
by aaronhall
Missing an E there

Code: Select all

$query = "SELCT * FROM users";

Posted: Sat Dec 02, 2006 1:08 pm
by screwcork
Hmmm... I've been twisting my brain for a missing "E" ? hehe! well, thanx alot! :) Works fine now!

*Taking mental note* "Check spelling, as well as code"

-Cheers!