Variable passed to each() is not an array or object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • assgar
    New Member
    • Aug 2006
    • 41

    Variable passed to each() is not an array or object

    I am having problems getting the user selected form info to inserted into the mysql database.
    I am also rec eving an error:
    Warning: Variable passed to each() is not an array or object in

    D:\web_server\w ebroot\common_l ist_process.php on line

    1) I can display the contents of the $op array (see below)
    2) Am I using the correct loop to unpact the array for inserting into the

    database?
    3) I have attempeted to correct the error: "Variable passed to each()

    is not an array or object".
    I don't understand why it is happening.
    4) I am willing to consider another approach to accomplishing this.




    [html]

    <html>
    <head></head>

    <body>
    <!-----------------------form processor---------------------------->
    <form action="../common_list_pro cess.php" method="post">
    <table>
    <tr>
    <td> <input type="submit" name="fee_butto n" value="Submit"
    style="color: #ff6600;font-weight:bold; margin-right: 5;"/> </td>
    </tr>

    </table>

    <?php
    display();//display form selection and input boxes
    ?>

    </form>
    </body>
    </html>
    [/html]

    [php]


    <?php

    /***------------display function------------**/
    //display form selection and input boxes

    function display()
    {

    $op = array();//create empty array

    /****This form consist of multiple rows like this****/
    echo "<table>\n" ;
    echo "<tr height=\"10\">\ n";
    echo "<td width=\"9%\" bgcolor=\"#fff8 dc\" align=\"\"><spa n class=\"style15 \">
    <input type=\"checkbox \" name=\"op[choice][]\" value=\"A1\">
    <span class=\"style1\ " >A1</span></span></td>
    <td width=\"2%\" bgcolor=\"#fff8 dc\" height=\"10\">
    <input type=\"text\" name=\"op[unit][]\" size=\"1\" maxlength=\"2\" value =\"$a_unit\"/></td>
    <td width=\"32%\" bgcolor=\"#ebea e0\" class=\"style11 \">General</td>\n";

    echo "<td width=\"9%\" bgcolor=\"#fff8 dc\" align=\"\"><spa n class=\"style15 \">
    <input type=\"checkbox \" name=\"op[choice][]\" value=\"A7\">
    <span class=\"style1\ " >A7</span></span></td>
    <td width=\"2%\" bgcolor=\"#ebea e0\" height=\"10\">
    <input type=\"text\" name=\"op[unit][]\" size=\"1\" maxlength=\"2\" value =\"$a_unit\"/></td>
    <td width=\"32%\" bgcolor=\"#ebea e0\" class=\"style11 \">Intermediate </td>\n";
    echo "</tr>\n";
    echo "</table>\n";

    return $op;

    }
    ?>


    [/php]


    [php]
    <?php
    /**---------common_list_pro cess.php-----------**/


    echo '<pre>',print_ r ($_POST, TRUE), '</pre>';//check array values

    //filter array
    if(is_array($_P OST['wohip']))
    {
    $fee_code = array_filter($_ POST['wohip']);

    }
    else
    {
    $fee_code = array($_POST['wohip']);
    $fee_code = array_filter($_ POST['wohip']);
    }

    //loop to insert values into database
    for($row = 0; $row < 3; $row++)
    {
    while(list($cho ice, $unit, $fee_money) = each($fee_code[$row]))
    {
    $choice; $unit";
    }

    /**** insert code goes here *****/

    }
    ?>



    [/php]





    /** -------------------results of page submission--------------------***/
    [op] => Array
    (
    [unit] => Array
    (
    [0] =>
    [1] =>
    [2] => 3
    [3] =>

    [145] =>
    [146] =>
    )

    [choice] => Array
    (
    [0] => A8
    )

    )

    Warning: Variable passed to each() is not an array or object in D:\web_server\w ebroot\common_l ist_process.php on line
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Code:
    each($fee_code[$row]))
    each returns the current array element. $fee_code[$row] is an array element so you are trying to return the current element from an element. Should be [PHP]each($fee_code)[/PHP]

    Comment

    • assgar
      New Member
      • Aug 2006
      • 41

      #3
      Originally posted by code green
      Code:
      each($fee_code[$row]))
      each returns the current array element. $fee_code[$row] is an array element so you are trying to return the current element from an element. Should be [PHP]each($fee_code)[/PHP]
      This problem has been solved

      Thanks

      Comment

      Working...