ecabrera Posted May 12, 2012 Share Posted May 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/262458-mysql_fetch_assoc-expects-parameter-1/ Share on other sites More sharing options...
.josh Posted May 12, 2012 Share Posted May 12, 2012 "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. Quote Link to comment https://forums.phpfreaks.com/topic/262458-mysql_fetch_assoc-expects-parameter-1/#findComment-1345034 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.