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

 

 

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.