justin7410 Posted January 9, 2014 Share Posted January 9, 2014 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 #9Array ( [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` = 1279Warning: 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 ? Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted January 9, 2014 Solution Share Posted January 9, 2014 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 156As for the problem, are you sure the field is called "date" and not "day"? Quote Link to comment Share on other sites More sharing options...
justin7410 Posted January 10, 2014 Author Share Posted January 10, 2014 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 156As 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 Quote Link to comment 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.