Jump to content

mysql_fetch_assoc() expects parameter 1


ecabrera

Recommended Posts

i get this error

 

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\website\viewvideos.php on line 25

 

$addviews = $views + 1;

$query = mysql_query("UPDATE headlines SET views='$addviews' WHERE id=$viewid");
$rows = mysql_fetch_assoc($query);

 

i dont get whats wrong

Link to comment
https://forums.phpfreaks.com/topic/262458-mysql_fetch_assoc-expects-parameter-1/
Share on other sites

"parameter 1" is the (optional) 2nd argument to mysql_query, where you specify your database connection resource.  If you do not specify the connection resource, php internally attempts to look for an established resource within the scope of the mysql_query() call.  The problem is that it is looking for the connection resource and can't find it and it is returning false, so the mysql_query() function is trying to use "false" (boolean value) as the connection resource.

 

So either

 

a) you have not established a connection to your database (you should be doing this with mysql_connect() to make the connection, and mysql_select_db() to select which database)

 

or

 

b) If you do have connection code somewhere before the code you posted, then your code is not within the scope of your established connection.  This commonly happens when you create a connection in the global scope, but then try to perform a query within a function.

 

 

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.