开发者

Selecting $_POST with a foreach statement returns error

So I开发者_开发知识库 have a form that can increase and decrease according to what the user adds to the page. To be able to handle unknown posts, I have set up a series of foreach loops that goes through each section in the table and unravels the array for each.

The form is a series of tables. Each table is for one category, and each row is a different part of it. Every row has 7 parts to it. The script circles through and gets the parts necessary to insert each column piece into the database.

On my personal home server the code returns no error and updates the database accordingly. On my paid hosting though I get an error. The error comes in after the the first foreach. It comes in at:

foreach($tablecontent as $key => $values)

This is the error: Warning: Invalid argument supplied for foreach() in /home/sariep5/public_html/werchris.com/circuitcheck/submit.php on line 14

My code is below:

<td><input type="text" maxlength="3" name="esd[8][eng]" value=""></td>
<td><input type="text" maxlength="3" name="esd[8][q2]" value=""></td>
<td><input type="text" maxlength="3" name="esd[8][loa]" value=""></td>
<td><input type="text" maxlength="3" name="esd[8][wire]" value=""></td>
<td><input type="text" maxlength="3" name="esd[8][verify]" value=""></td>
<td><input type="text" maxlength="3" name="esd[8][assy]" value=""></td>
<td><input type="text" maxlength="3" name="esd[8][q4]" value=""></td>

That is the HTML part of the form. Sections just like that are created only with different parts to the name. So esd could be any other category, 8 increments, and the other 7 are the same in every section.

foreach ($_POST as $table => $tablecontent) { 
    foreach($tablecontent as $key => $values) {
        foreach($values as $row => $value) {
            $value = strip_tags(htmlspecialchars($value));
            $row = strip_tags(htmlspecialchars($row));
            $key = strip_tags(htmlspecialchars($key));
            mysql_query("UPDATE tablecontent SET ".$row." = '$value'
                         WHERE id='$key'");
        }
    } 
}

Thanks!


That's simple foreach($tablecontent as $key => $values) error there means $tablecontent isn't an array

Warning: Invalid argument supplied for foreach() in /home/sariep5/public_html/werchris.com/circuitcheck/submit.php on line 14

Try a var_dump($tablecontent); there

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜