471,066 Members | 1,191 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

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

41
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\webroot\common_list_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_process.php" method="post">
<table>
<tr>
<td> <input type="submit" name="fee_button" 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=\"#fff8dc\" align=\"\"><span class=\"style15\">
<input type=\"checkbox\" name=\"op[choice][]\" value=\"A1\">
<span class=\"style1\" >A1</span></span></td>
<td width=\"2%\" bgcolor=\"#fff8dc\" height=\"10\">
<input type=\"text\" name=\"op[unit][]\" size=\"1\" maxlength=\"2\" value =\"$a_unit\"/></td>
<td width=\"32%\" bgcolor=\"#ebeae0\" class=\"style11\">General</td>\n";

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

return $op;

}
?>


[/php]


[php]
<?php
/**---------common_list_process.php-----------**/


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

//filter array
if(is_array($_POST['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($choice, $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\webroot\common_list_process.php on line
Apr 19 '07 #1
2 15300
code green
1,726 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. 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]
Apr 20 '07 #2
assgar
41
Expand|Select|Wrap|Line Numbers
  1. 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
Apr 21 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Randell D. | last post: by
7 posts views Thread by Greg Collins [MVP] | last post: by
23 posts views Thread by Russ Chinoy | last post: by
13 posts views Thread by Justcallmedrago | last post: by
9 posts views Thread by Animesh K | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.