Namtip Posted September 24, 2010 Share Posted September 24, 2010 Problem: "Warning: extract() expects parameter 1 to be array, null given in C:\x\xampp\htdocs\pages\user_personal.php on line 32" - error also found on lines 33 and 38. and none of the information is displayed. Goal: I'm trying to retrieve profile information and multiple user inserted pictures and display the pictures through a while loop from one query. <?php$query = 'SELECT u.name_id, i.bio, i.exhib, p.product_code FROM user u LEFT JOIN profile i ON u.name_id = i.name_id LEFT JOIN ecomm_products p ON u.name_id = p.product_code WHERE u.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '" and p.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '"'; $result = mysql_query($query, $db) or die(mysql_error());extract($bio); //line 32extract($exhib); //line 33$odd = true;while ($row = mysql_fetch_array($result)) { echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">'; $odd = !$odd; extract($rows); line 38 echo '<td><a href="' . $dir . '/' . $row['product_code'] . '.jpg">'; echo '<img src="' . $thumbdir . '/' . $row['product_code'] . '.jpg">'; echo '</a></td>'; echo '</tr>'; } echo "</table>"; echo "<p>";?> <ul> <li>Biography: <?php echo $bio; ?></li> <li>Exhibitions: <?php echo $exhib; ?></li> </ul> Link to comment https://forums.phpfreaks.com/topic/214249-extract-expects-parameter-1-to-be-array-no-information-displayed/ Share on other sites More sharing options...
BlueSkyIS Posted September 24, 2010 Share Posted September 24, 2010 $bio and $exhib must be arrays, but they are null Link to comment https://forums.phpfreaks.com/topic/214249-extract-expects-parameter-1-to-be-array-no-information-displayed/#findComment-1114845 Share on other sites More sharing options...
Namtip Posted September 24, 2010 Author Share Posted September 24, 2010 This works. <?php$query = 'SELECT u.name_id, i.bio, i.exhib, p.product_code FROM user u LEFT JOIN profile i ON u.name_id = i.name_id LEFT JOIN ecomm_products p ON u.name_id = p.product_code WHERE u.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '" and p.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '"'; $result = mysql_query($query, $db) or die(mysql_error());$row = mysql_fetch_array($result);extract($row);mysql_free_result($result);mysql_close($db); ?> <ul> <li>Biography: <?php echo $bio; ?></li> <li>Exhibitions: <?php echo $exhib; ?></li> </ul> but i want try to loop out the pictures it says different errors. This gives out this error "Warning: mysql_fetch_array(): 5 is not a valid MySQL result resource in C:\x\xampp\htdocs\pages\user_personal.php on line 54" <?php$query = 'SELECT u.name_id, i.bio, i.exhib, p.product_code FROM user u LEFT JOIN profile i ON u.name_id = i.name_id LEFT JOIN ecomm_products p ON u.name_id = p.product_code WHERE u.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '" and p.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '"'; $result = mysql_query($query, $db) or die(mysql_error());$row = mysql_fetch_array($result);extract($row);mysql_free_result($result);mysql_close($db); ?> <ul> <li>Biography: <?php echo $bio; ?></li> <li>Exhibitions: <?php echo $exhib; ?></li> </ul> <p><a href="update_profile.php">Update Profile</a> |<a href="upload_image.php">Upload Work</a> |<a href="update_account.php">Update Account</a> |<a href="delete_account.php">Delete Account</a> |<a href="logout.php">Sign out</a> </p></body></html><?php$odd = true;while ($row = mysql_fetch_array($result)) { // line 54 echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">'; $odd = !$odd; extract($rows); echo '<td><a href="' . $dir . '/' . $row['product_code'] . '.jpg">'; echo '<img src="' . $thumbdir . '/' . $row['product_code'] . '.jpg">'; echo '</a></td>'; echo '</tr>'; } echo "</table>"; echo "<p>";?> Is it not possible to pull two different results from the array? Do I need to give variables to the mysql WHERE function in the SELECT table? Am I making sense? Link to comment https://forums.phpfreaks.com/topic/214249-extract-expects-parameter-1-to-be-array-no-information-displayed/#findComment-1114854 Share on other sites More sharing options...
BlueSkyIS Posted September 24, 2010 Share Posted September 24, 2010 maybe because you freed the result before you tried to use it again: mysql_free_result($result); // $result is no longer a valid mysql resource Link to comment https://forums.phpfreaks.com/topic/214249-extract-expects-parameter-1-to-be-array-no-information-displayed/#findComment-1114855 Share on other sites More sharing options...
Namtip Posted September 24, 2010 Author Share Posted September 24, 2010 <?php $query = 'SELECT u.name_id, i.bio, i.exhib, p.product_code FROM user u LEFT JOIN profile i ON u.name_id = i.name_id LEFT JOIN ecomm_products p ON u.name_id = p.product_code WHERE u.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '" and p.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '"'; $result = mysql_query($query, $db) or die(mysql_error()); $row = mysql_fetch_array($result); extract($row); ?> <html> <head></head> <body> <ul> <li>Biography: <?php echo $bio; ?></li> <li>Exhibitions: <?php echo $exhib; ?></li> </ul> <p><a href="update_profile.php">Update Profile</a> | <a href="upload_image.php">Upload Work</a> | <a href="update_account.php">Update Account</a> | <a href="delete_account.php">Delete Account</a> | <a href="logout.php">Sign out</a> </p> <?php $odd = true; while ($row = mysql_fetch_array($result)) { echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">'; $odd = !$odd; extract($rows); echo '<td><a href="' . $dir . '/' . $row['product_code'] . '.jpg">'; echo '<img src="' . $thumbdir . '/' . $row['product_code'] . '.jpg">'; echo '</a></td>'; echo '</tr>'; } echo "</table>"; echo "<p>"; ?> </body> </html> No error messages display but no photos loop either. Sorry to be a bother. Link to comment https://forums.phpfreaks.com/topic/214249-extract-expects-parameter-1-to-be-array-no-information-displayed/#findComment-1114861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.