vigv Posted April 7, 2011 Share Posted April 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/232943-mysql_fetch_row-error/ Share on other sites More sharing options...
3raser Posted April 7, 2011 Share Posted April 7, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232943-mysql_fetch_row-error/#findComment-1198079 Share on other sites More sharing options...
PFMaBiSmAd Posted April 7, 2011 Share Posted April 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/232943-mysql_fetch_row-error/#findComment-1198080 Share on other sites More sharing options...
vigv Posted April 7, 2011 Author Share Posted April 7, 2011 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. :/ Quote Link to comment https://forums.phpfreaks.com/topic/232943-mysql_fetch_row-error/#findComment-1198082 Share on other sites More sharing options...
gibigbig Posted April 7, 2011 Share Posted April 7, 2011 $query= mysql_query("SELECT * FROM table WHERE field = 'value'"); while ($row = mysql_fetch_assoc($query)) { // code here example: used as $row['field_name'] or $row['username'] etc... } Quote Link to comment https://forums.phpfreaks.com/topic/232943-mysql_fetch_row-error/#findComment-1198085 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.