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
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.

Link to comment
Share on other sites

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. :/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.