我正在尝试从每个更改为foreach,但是我无法使其正常工作。
我不断收到错误消息,指出PHP Parse错误:语法错误,意外的')',但没有意外的')'吗????
感谢您的帮助!
// Splits textarea lines into an array.
$newEntry = explode("\n",$txtarea);
// Obtain the number of new entries.
$x = 0;
while (each($newEntry)) {
$x++;
}
reset($newEntry);
//---------------------------------------------------
if ($_POST['groups']) {
while (list ($x_key, $x_gid) = each ($_POST['groups'])) {
$groupsql = "INSERT INTO " . TABLE_GROUPS . " VALUES ($id,$x_gid)";
runQuery($groupsql);
}
}
这就是帖子中的内容
Array ( [id] => 44 [lastname] => Anderson [firstname] => John [middlename] => William [address_zip_0] => 9922
[nickname] => Will [address_state_0] => Denver, CO [x_gid] => 123T [pictureURL] => pixtest.jpg
[address_type_0] => testtype [address_primary_select] => test field address primary [address_line1_0] => 2 [address_city_0] => denver
[address_phone1_0] => 111-222-3333 [address_email] => test@test.com [address_phone2_0] => 999-888-7777 [status2] => [notes] => test 1122
[address_websites] => www.test.com [address_additionaldata] => [groups] => Array ( [0] => 55 ) [address_type_1] => [address_line1_1] =>
[address_line2_1] => [address_city_1] => [address_state_1] => [address_zip_1] => [address_phone1_1] => [address_phone2_1] => [addnum] => 1 )
答案 0 :(得分:1)
if ($_POST['groups']) {
while (list ($x_key, $x_gid) = each ($_POST['groups'])) {
$groupsql = "INSERT INTO " . TABLE_GROUPS . " VALUES ($id,$x_gid)";
runQuery($groupsql);
}
}
已转换为使用foreach()
if ($_POST['groups']) {
foreach($_POST['groups'] as $g) {
$groupsql = "INSERT INTO " . TABLE_GROUPS . " VALUES ({$_POST['id']},$g)";
runQuery($groupsql);
}
}
注释:
-巨大的安全性问题,原始帖子值会像这样进入db