Jump to content

mysql_fetch_assoc() expects parameter 1 to be resource, boolean given ISSUE


justin7410
Go to solution Solved by requinix,

Recommended Posts

Hey guys,

 

I am currently facing an issue with my profile.php page for my website.

 

i have a function that is grabbing information of a logged in user grabbing his ID and his data array combining the 2 and creating a variable that will let me echo out the info for the end user on their profile page.

 

the function that is creating an error :

function user_data($user_id){$data = array();
$user_id = (int)$user_id;


$func_num_args = func_num_args();
$func_get_args = func_get_args();


if ($func_num_args > 1) {
unset($func_get_args[0]);


$fields = '`' . implode('`, `', $func_get_args) . '`' ;
$query = ("SELECT $fields FROM `users` WHERE `user_id` = $user_id");
echo $query . '<br><br>' ;         < ---- ADDED FOR DEBUGGING --------- NOT PART OF CODE
$run = mysql_query($query);
print_r($run);                     < ---- ADDED FOR DEBUGGING --------- NOT PART OF CODE
echo '<br><br>';                   < ---- ADDED FOR DEBUGGING --------- NOT PART OF CODE
$data = mysql_fetch_assoc($run); 
print_r($data) . '<br><br>';       < ---- ADDED FOR DEBUGGING --------- NOT PART OF CODE

return $data;
die();                             < ---- ADDED FOR DEBUGGING --------- NOT PART OF CODE
}
}

The function seems to work properly when printing the array and the query , firing the query independently in sql and getting a TRUE;

 

Results:

 

SELECT `user_id`, `username`, `password`, `email`, `gender`, `country`, `month`, `day`, `year`, `pass_recover`, `type` FROM `users` WHERE `user_id` = 1279

Resource id #9

Array ( [user_id] => 1279 [username] => admin00100 [password] => 53dd9c6005f3cdfc5a69c5c07388016d => admin@admin.com [gender] => m [country] => AF [month] => 1 [day] => 1 [year] => 2005 [pass_recover] => 0 [type] => 0 ) SELECT `username`, `email`, `gender`, `country`, `month`, `date`, `year` FROM `users` WHERE `user_id` = 1279




Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/justin/public_html/core/functions/users.php on line 156

 

 

 

Line 156 of this file is that Function above ^

 

I dont understand why i am getting this error : 

 

I understand that i need the $query to fire correctly and return a resource to the fetch_assoc() , but as it shows above the resource is being provided and is still returning as a string ???.

 

any suggestions ?

Link to comment
Share on other sites

  • Solution

but as it shows above the resource is being provided and is still returning as a string ???.

Not quite: it shows the function being called twice, with the first time working

SELECT `user_id`, `username`, `password`, `email`, `gender`, `country`, `month`, `day`, `year`, `pass_recover`, `type` FROM `users` WHERE `user_id` = 1279
Resource id #9

Array ( [user_id] => 1279 [username] => admin00100 [password] => 53dd9c6005f3cdfc5a69c5c07388016d [email] => admin@admin.com [gender] => m [country] => AF [month] => 1 [day] => 1 [year] => 2005 [pass_recover] => 0 [type] => 0 )
and the second time failing

SELECT `username`, `email`, `gender`, `country`, `month`, `date`, `year` FROM `users` WHERE `user_id` = 1279




Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/justin/public_html/core/functions/users.php on line 156
As for the problem, are you sure the field is called "date" and not "day"?
Link to comment
Share on other sites

Not quite: it shows the function being called twice, with the first time working

SELECT `user_id`, `username`, `password`, `email`, `gender`, `country`, `month`, `day`, `year`, `pass_recover`, `type` FROM `users` WHERE `user_id` = 1279
Resource id #9

Array ( [user_id] => 1279 [username] => admin00100 [password] => 53dd9c6005f3cdfc5a69c5c07388016d [email] => admin@admin.com [gender] => m [country] => AF [month] => 1 [day] => 1 [year] => 2005 [pass_recover] => 0 [type] => 0 )
and the second time failing

SELECT `username`, `email`, `gender`, `country`, `month`, `date`, `year` FROM `users` WHERE `user_id` = 1279




Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/justin/public_html/core/functions/users.php on line 156
As for the problem, are you sure the field is called "date" and not "day"?

 

Good eye .. sir

 

that was it, the field was not matching.

 

Thank you very much

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.