Page 1 of 1

mysql_fetch_assoc() expects parameter 1 to be resource......

Posted: Sat Jan 14, 2012 10:46 am
by Shahlin
I Tried Creating A Profile Page!

But i always get an error : "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\php\Profile\core\inc\user.inc.php on line 28"
<?php
// fetches all of the users from the table!
function fetch_users() {
	$result = mysql_query ("SELECT `user_id` AS `id`, `user_username` AS `username` FROM `users`") ;
	$users = array () ;

while (($row = mysql_fetch_assoc($result)) !== false) {
	$users [] = $row ;

	}	
	  return $users ;
}

function fetch_user_info ($uid) {
	$uid = (int)$uid;
	$sql = "SELECT 
				`user_username` AS `username`
				`user_firstname` AS `firsntame`
				`user_lastname` AS `lastname`
				`user_email` AS `email`
				`user_about` AS `about`
				`user_location` AS `location`
				`user_gender` AS `gender` 
			FROM `users`
			WHERE `user_id`= ($uid)" ;
	$result = mysql_query ($sql) ;
	
	return mysql_fetch_assoc ($result) ; //THIS LINE HAS AN ERROR!
}
?>

Re: mysql_fetch_assoc() expects parameter 1 to be resource..

Posted: Sat Jan 14, 2012 12:05 pm
by Temor
you need to separate your SQL with commas.
 $sql = "SELECT
                                `user_username` AS `username`,
                                `user_firstname` AS `firsntame`,
                                `user_lastname` AS `lastname`,
                                `user_email` AS `email`,
                                `user_about` AS `about`,
                                `user_location` AS `location`,
                                `user_gender` AS `gender`
                        FROM `users`
                        WHERE `user_id`= ($uid)" ;
ยจ

next time, echo mysql_error(); after your SQL. It will tell you exactly what is wrong :)

Re: mysql_fetch_assoc() expects parameter 1 to be resource..

Posted: Sat Jan 14, 2012 6:59 pm
by Shahlin
Thanks!