[RESOLVED] WARNING: mysql_fetch_row()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
screwcork
Forum Newbie
Posts: 16
Joined: Thu Apr 13, 2006 3:25 am
Location: Oslo - Norway

[RESOLVED] WARNING: mysql_fetch_row()

Post 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
Last edited by screwcork on Sat Dec 02, 2006 1:05 pm, edited 1 time in total.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Missing an E there

Code: Select all

$query = "SELCT * FROM users";
screwcork
Forum Newbie
Posts: 16
Joined: Thu Apr 13, 2006 3:25 am
Location: Oslo - Norway

Post 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!
Post Reply