Wizzuriz Posted August 19, 2011 Share Posted August 19, 2011 Hello, I´m having a problem with some code. this is the code. <?php // fetches all of the users from the table. ( this one works just fine.) 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; } // fetches profile information for the given user. function fetch_user_info($uid){ $uid =(int)$uid; $sql = "select `user_username` AS `username`, `user_firstname` AS `firstname`, `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); // this is where there should be a problem, line 33 just below. return mysql_fetch_assoc($result); } ?> This is my error. Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/user_profile/core/inc/user.inc.php on line 33 please let me know if you can see the problem or if you need more information. best regards Wizzuriz Quote Link to comment https://forums.phpfreaks.com/topic/245236-hello-all-i%C2%B4m-new-to-programming-but-i-do-learn-much-each-day/ Share on other sites More sharing options...
Maq Posted August 19, 2011 Share Posted August 19, 2011 In the future, please place OR tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/245236-hello-all-i%C2%B4m-new-to-programming-but-i-do-learn-much-each-day/#findComment-1259573 Share on other sites More sharing options...
Maq Posted August 19, 2011 Share Posted August 19, 2011 Your query is probably failing. Change this line to: $result = mysql_query($sql) or die(mysql_error()); to figure out what the error is. Quote Link to comment https://forums.phpfreaks.com/topic/245236-hello-all-i%C2%B4m-new-to-programming-but-i-do-learn-much-each-day/#findComment-1259575 Share on other sites More sharing options...
thepales Posted August 19, 2011 Share Posted August 19, 2011 try changing `` for ' (add simple quotes) Quote Link to comment https://forums.phpfreaks.com/topic/245236-hello-all-i%C2%B4m-new-to-programming-but-i-do-learn-much-each-day/#findComment-1259576 Share on other sites More sharing options...
Maq Posted August 19, 2011 Share Posted August 19, 2011 try changing `` for ' (add simple quotes) Actually, don't do that. Backtics are for escaping table/column names for reserved MySQL words. Single quotes are used primarily for values. Quote Link to comment https://forums.phpfreaks.com/topic/245236-hello-all-i%C2%B4m-new-to-programming-but-i-do-learn-much-each-day/#findComment-1259578 Share on other sites More sharing options...
thepales Posted August 19, 2011 Share Posted August 19, 2011 Oh, I am sorry, I didn`t notice that they were not values. So don`t change them to simple quotes. Quote Link to comment https://forums.phpfreaks.com/topic/245236-hello-all-i%C2%B4m-new-to-programming-but-i-do-learn-much-each-day/#findComment-1259579 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.