Warning: extract() expects parameter 1 to be array

  • cerio
  • Proficient
  • Proficient
  • User avatar
  • Posts: 263
  • Loc: UK

Post 3+ Months Ago

I'm not sure if this is related to the webhost's change to PHP 5.3 too but there is just one other area that is suddenly causing a problem, though it was fine for 4 years until recently and is not to do with date format this time. It is this...


The error message is...
Warning: extract() expects parameter 1 to be array, boolean given in .../httpdocs/admin/product/modify.php on line 20

Notice: Undefined variable: cat_id in .../httpdocs/admin/product/modify.php on line 52

and the code it seems to refer to in the file modify.php is this....

Code: [ Select ]
<?php
if (!defined('WEB_ROOT')) {
    exit;
}

// make sure a product id exists
if (isset($_GET['productId']) && $_GET['productId'] > 0) {
    $productId = $_GET['productId'];
} else {
    // redirect to index.php if product id is not present
    header('Location: index.php');
}

// get product info
$sql = "SELECT *
    FROM tbl_product pd, tbl_category cat
        WHERE pd.pd_id = $productId AND pd.cat_id = cat.cat_id";
$result = mysql_query($sql) or die('Cannot get product. ' . mysql_error());
$row  = mysql_fetch_assoc($result);
extract($row);

// get category list
$sql = "SELECT cat_id, cat_parent_id, cat_name
    FROM tbl_category
        ORDER BY cat_id";
$result = dbQuery($sql) or die('Cannot get Product. ' . mysql_error());

$categories = array();
while($row = dbFetchArray($result)) {
    list($id, $parentId, $name) = $row;
    
    if ($parentId == 0) {
        $categories[$id] = array('name' => $name, 'children' => array());
    } else {
        $categories[$parentId]['children'][] = array('id' => $id, 'name' => $name);    
    }
}    

//echo '<pre>'; print_r($categories); echo '</pre>'; exit;

// build combo box options
$list = '';
foreach ($categories as $key => $value) {
    $name   = $value['name'];
    $children = $value['children'];
    
    $list .= "<optgroup label=\"$name\">";
    
    foreach ($children as $child) {
        $list .= "<option value=\"{$child['id']}\"";
        
        if ($child['id'] == $cat_id) {
            $list .= " selected";
        }
        $list .= ">{$child['name']}</option>";
    }
    
    $list .= "</optgroup>";
}
?>
<form action="processProduct.php?action=modifyProduct&productId=<?php echo $productId; ?>" method="post" enctype="multipart/form-data" name="frmAddProduct" id="frmAddProduct">
<p align="center" class="formTitle">Modify Product</p>

<table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
 <tr>
  <td width="150" class="label">Category</td>
  <td class="content"> <select name="cboCategory" id="cboCategory" class="box">
   <option value="" selected>-- Choose Category --</option>
<?php
    echo $list;
?>    
  1. <?php
  2. if (!defined('WEB_ROOT')) {
  3.     exit;
  4. }
  5. // make sure a product id exists
  6. if (isset($_GET['productId']) && $_GET['productId'] > 0) {
  7.     $productId = $_GET['productId'];
  8. } else {
  9.     // redirect to index.php if product id is not present
  10.     header('Location: index.php');
  11. }
  12. // get product info
  13. $sql = "SELECT *
  14.     FROM tbl_product pd, tbl_category cat
  15.         WHERE pd.pd_id = $productId AND pd.cat_id = cat.cat_id";
  16. $result = mysql_query($sql) or die('Cannot get product. ' . mysql_error());
  17. $row  = mysql_fetch_assoc($result);
  18. extract($row);
  19. // get category list
  20. $sql = "SELECT cat_id, cat_parent_id, cat_name
  21.     FROM tbl_category
  22.         ORDER BY cat_id";
  23. $result = dbQuery($sql) or die('Cannot get Product. ' . mysql_error());
  24. $categories = array();
  25. while($row = dbFetchArray($result)) {
  26.     list($id, $parentId, $name) = $row;
  27.     
  28.     if ($parentId == 0) {
  29.         $categories[$id] = array('name' => $name, 'children' => array());
  30.     } else {
  31.         $categories[$parentId]['children'][] = array('id' => $id, 'name' => $name);    
  32.     }
  33. }    
  34. //echo '<pre>'; print_r($categories); echo '</pre>'; exit;
  35. // build combo box options
  36. $list = '';
  37. foreach ($categories as $key => $value) {
  38.     $name   = $value['name'];
  39.     $children = $value['children'];
  40.     
  41.     $list .= "<optgroup label=\"$name\">";
  42.     
  43.     foreach ($children as $child) {
  44.         $list .= "<option value=\"{$child['id']}\"";
  45.         
  46.         if ($child['id'] == $cat_id) {
  47.             $list .= " selected";
  48.         }
  49.         $list .= ">{$child['name']}</option>";
  50.     }
  51.     
  52.     $list .= "</optgroup>";
  53. }
  54. ?>
  55. <form action="processProduct.php?action=modifyProduct&productId=<?php echo $productId; ?>" method="post" enctype="multipart/form-data" name="frmAddProduct" id="frmAddProduct">
  56. <p align="center" class="formTitle">Modify Product</p>
  57. <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
  58.  <tr>
  59.   <td width="150" class="label">Category</td>
  60.   <td class="content"> <select name="cboCategory" id="cboCategory" class="box">
  61.    <option value="" selected>-- Choose Category --</option>
  62. <?php
  63.     echo $list;
  64. ?>    

There is a bit more code on the page but I copied way past line 52, so hope that will do.

Again, I don't know anything about arrays or variables, I'm afraid.

The effect of that problem is, if I opened the site's admin, having left it logged in, it used to display the last admin page I was on, showing a list of categories or items etc., now it gives this...
Image

It still works, I just have to choose the section from the menu but, as I say, it didn't used to display these errors, it properly displayed the last page I was on.

If I've logged out and log in afresh I don't get that scrambled page since it automatically takes me to the admin home page when newly logged in, it's only when I go back after closing the page but still logged in.

It's not a huge problem, it's just irritating and I don't know why it suddenly changed when it was fine for years and I don't think I changed anything on that file at all.

Regards,
Cerio
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Put the following:
PHP Code: [ Select ]
echo "<pre>";var_dump($result);var_dump($row);echo "</pre>";

on line 21 and post what it shows.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

As a side note, the function extract could be overwriting a variable... like the $cat_id for instance...

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 144 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.