Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
I get this co-occurant error and I can't figure out what to do about it:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\xampp\htdocs\Project\Func\user.func.php on line 44
The code snippet, looks like this:
42 $user_id = mysql_real_escape_string($user_id);
43 $sql = mysql_query("SELECT `username` FROM `users` WHERE user_id = $user_id");
44 $row = mysql_fetch_assoc($sql);
45 return $row['username'];
I understand that it's the mysql_fetch_assoc() command that's triggering the error, but why?
Can anyone please direct me to the error in my code? I'd appreciate any help.
Thanks.