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

Ask about a PHP problem here.
Post Reply
Shahlin
Posts: 49
Joined: Sat Jan 14, 2012 10:35 am

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

Post 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!
}
?>
Just A PHP Beginner!
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

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

Post 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 :)
Shahlin
Posts: 49
Joined: Sat Jan 14, 2012 10:35 am

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

Post by Shahlin »

Thanks!
Just A PHP Beginner!
Post Reply