473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 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 15481
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

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

Similar topics

2
by: Randell D. | last post by:
I have a script (below) that can be passed an array and it will dump the contents of the array in to an html table - I use it during development so its nothing sexy. It handles multidimsional...
6
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid =...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
7
by: Greg Collins [MVP] | last post by:
Hi, I couldn't find what I was looking for by searching the newsgroup, but perhaps these have already been discussed somewhere. This is a bit long with a lot of interrelated questions. What I've...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
3
by: Skip | last post by:
OK, I'm a novice in JS but have lots of coding experience. I am trying to accomplish something that would seem somewhat simple - BUT IT'S NOT. I have a basic window that calls another window...
13
by: Justcallmedrago | last post by:
How would you declare and assign a variable inside a function THAT HAS THE NAME OF A PARAMETER YOU PASSED example: when you call createvariable("myvariable") it will declare the variable...
9
by: Animesh K | last post by:
Hello All: I want to have some re-usable variables, which can be used inside (as well as outside) objects. The use of GLOBALS array is one option, but then I will have to keep track of "reserved...
3
by: linghuyuanye | last post by:
I just learnt php yesterday. I have a problem whenever I submit the form on my webpage.It gives me Warning: Variable passed to each() is not an array or object. The array part in my form would be the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.