Namtip Posted August 14, 2010 Share Posted August 14, 2010 I'm a newbie . I've been stuck on this error message for 2 days: I get this error message: extract() expects parameter 1 to be array, boolean given in C:\x\xampp\htdocs\user_personal.php on line 30 <?php $query = 'SELECT about_me, job, hobbies, contact FROM site_user u JOIN site_user_profile p ON u.user_id = p.user_id WHERE username = "' . mysql_real_escape_string($_SESSION['username'], $db) . '"'; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_array($result); extract($row); mysql_free_result($result); mysql_close($db); ?> I think joining table is hard, I just want to create a profile that would be linked to a user name. Please be my friend and help me so I can have PHP phun time. Quote Link to comment https://forums.phpfreaks.com/topic/210685-extract-expects-parameter-1-to-be-array-help-please/ Share on other sites More sharing options...
Pikachu2000 Posted August 14, 2010 Share Posted August 14, 2010 The query is failing and returning the boolean value FALSE to the extract() function. Echo the query to the screen then paste it into phpMyAdmin and see what, if any results you get. Quote Link to comment https://forums.phpfreaks.com/topic/210685-extract-expects-parameter-1-to-be-array-help-please/#findComment-1099078 Share on other sites More sharing options...
PFMaBiSmAd Posted August 14, 2010 Share Posted August 14, 2010 The error means that your query matched zero rows (the WHERE clause was FALSE). You should use mysql_num_rows() to find out if your query matched anything before you attempt to fetch and access the data. As to why your query did not match anything, are you sure your $_SESSION variable contains what you expect? What do you get if you echo $query? Quote Link to comment https://forums.phpfreaks.com/topic/210685-extract-expects-parameter-1-to-be-array-help-please/#findComment-1099079 Share on other sites More sharing options...
Namtip Posted August 14, 2010 Author Share Posted August 14, 2010 Thanks guys you're pros. Ah, there isn't any data for the database to retrieve. Could this be why the error message comes up? What should I enter into my code if I want it to display nothing without an error message? This is what it said when I echo'd the query SELECT about_me, job, hobbies, contact FROM site_user u JOIN site_user_profile p ON u.user_id = p.user_id WHERE username = "Russell" Quote Link to comment https://forums.phpfreaks.com/topic/210685-extract-expects-parameter-1-to-be-array-help-please/#findComment-1099161 Share on other sites More sharing options...
trq Posted August 14, 2010 Share Posted August 14, 2010 if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { // use data } else { // no data found. } } else { // query failed } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210685-extract-expects-parameter-1-to-be-array-help-please/#findComment-1099163 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.