我有一个表单,它从一个名为 question3 的输入数组中收集信息,然后我将它发布到进程 php 页面,它不会向数据库中的评论字段写入任何内容,或者取决于我尝试将“数组”写入所有评论字段的爆炸函数.
任何意见,将不胜感激。
这是代码:
foreach ($_POST['question3'] as $key3 => $ans3) {
$write = (explode(" ",$_POST['question3']));
echo "</BR>";
mysql_query("UPDATE trn SET comments = '$write' WHERE id = '$key3'");
if (mysql_affected_rows() == 1) {
$sql1 = "SELECT * FROM trn WHERE id = '$key3'";
$res1 = mysql_query($sql1);
while ($row1 = mysql_fetch_assoc($res1)) {
$userid = $row1['usr_id'];
$certificate_name = $row1['certificate_name'];
$comment = $row1['comments'];
} //$row1 = mysql_fetch_assoc($res1)
if ($comment == NULL) {
echo "Successfully updated <font color=blue>$certificate_name</font> to comments = <font color=green>y</font>";
} else {
$sql2 = "SELECT * FROM ex_usrs WHERE id = '$userid'";
$res2 = mysql_query($sql2);
while ($row2 = mysql_fetch_assoc($res2)) {
$fn = $row2['firstname'];
$ln = $row2['lastname'];
} //$row2 = mysql_fetch_assoc($res2)
echo "Successfully updated <font color=blue>$fn $ln</font> to comments = <font color=green>y</font>";
}
} //mysql_affected_rows() == 1
} //$_POST['question'] as $key => $ans
这是 var_dump 显示的内容:
array(4) {
[743]=> array(1) {
[0]=> string(5) "Mercy"
}
[748]=> array(1) {
[0]=> string(6) "Anelie"
}
[749]=> array(1) {
[0]=> string(6) "Bealah"
}
[750]=> array(1) {
[0]=> string(4) "Theo"
}
}
这些值是从之前发布的表单页面中获得的。这是一个内部网站,没有外部链接,所以不担心黑客攻击。
这是我要输入的表单部分。
$sql7 = "SELECT * FROM trn WHERE course_id = '$sel_course_id' AND date_1 = '$sel_date_1' and date_2 = '$sel_date_2'";
$res6 = mysql_query($sql7);
while ($row6 = mysql_fetch_assoc($res6)) {
$rowid6 = $row6['id'];
$uid5 = $row6['usr_id'];
$certificate_name5 = $row6['certificate_name'];
$certificate_issued5 = $row6['certificate_issued'];
$comm7 = $row6['comments'];
if ($uid5 == 'x') {
echo "<tr>";
echo "<td>";
$checked7 = "";
if ($comm7 == '') {
$checked7 = "$comm7";
} else {
$checked7 = "$comm7";
}
echo "<input name='question3[$rowid6][]' type='text' style='width: 675px; height: 30px;' type='text' maxlength='160' $checked7 value='$comm7' />$certificate_name5" . " - Not registered on users table";
echo "</td>";
} else {
$sql8 = "SELECT * FROM ex_usrs WHERE id = '$uid5'";
$res7 = mysql_query($sql8);
while ($row7 = mysql_fetch_assoc($res7)) {
$fn6 = $row7['firstname'];
$ln6 = $row7['lastname'];
$com7 = $row7['comments'];
}
$checked8 = "$comm7";
if ($comm7 == '') {
$checked8 = "$comm7";
} else {
$checked8 = "$comm7";
}
echo " <tr>";
echo " <td>";
echo "<input name='question3[$rowid6][]' type='text' style='width: 675px; height: 30px;' type='text' maxlength='160' $checked8 value='$comm7'/>$fn6 $ln6";
echo "</td>";
}
}
echo " </tr>";
echo " </table>";
echo " </td>";
echo " </tr>";
echo " <tr>";
echo " <td> </td>";
echo " <td><input name='Submit1' type='submit' value='submit'></td>";
echo " </tr>";
echo " </table>";
echo "</form>";