Jump to content

mysql_fetch_row() error.


vigv

Recommended Posts

Hello!

 

I've been trying to work on a small project of mine but I keep encountering this:

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\book-suggestion\test.php on line 21

 

In test.php, this is the only PHP code I seem to have and I haven't found anything wrong with it. For additional assurance, I copy-pasted the SQL statement directly from phpmyAdmin but it continues to give me an error so I know for a fact that the SQL query works and there is a result for such a query.

 

$db = mysql_connect("127.0.0.1",$db_user,$db_password, $db_name);
if(!isset($db)) {
	echo 'Error connecting to database...';
} else {
	echo 'Success.';
}
$query = mysql_query("SELECT * FROM `book-listing` WHERE 1");
$row = mysql_fetch_row($query);

 

Any help with this?

I've tried var_dump() and it returns boolean(false). Can't seem to figure out what the mistake is.

Link to comment
https://forums.phpfreaks.com/topic/232943-mysql_fetch_row-error/
Share on other sites

The error means that your mysql_query() failed due to an error. You can use mysql_error() to find out specifically why, but in your case it is because you haven't selected a database.

 

The 4th parameter of the mysql_connect() is NOT the database name, it is a flag that determines if a new connection should be formed.

 

You either need to use mysql_select_db to select a database to use or you need to specify the database name in the query.

Not sure if this is an actual error. I get this when using WAMP.

 

Also, is the WHERE statement correct?

 

$query = mysql_query("SELECT * FROM `book-listing` WHERE 1");

 

I've never seen it done that way. o.o

 

Yeah, I copied that straight from phpmyAdmin. I haven't seen it done that way before, either.

Thanks, PFMaBiSmAd, I didn't realize that. I was pretty convinced that I could select the database using the fourth parameter. :/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.