【发布时间】:2013-12-15 12:50:08
【问题描述】:
我有这个脚本,我想将表单中的值发布到我的数据库中。我想将多个文本框发布到一个表单中。
问题是,只有最后一个文本框得到更新。
<form action='' method='post'>
<?php
for ($i=0; $i<$count; $i++) {
echo "<input type='text' name='".$i."' />
<input type='hidden' name='img_id' value='".$img_id."' />
<input type='hidden' name='loop' value='".$i."' />";
}
?>
<input type='submit' value='Update' name='update' /></form>
<?php
if (isset($_POST['update'])) {
//now i need help
$query = "UPDATE photos SET description = '".$_POST[$_POST['loop']]."' WHERE id = '".$img_id."'";
$res = mysql_query($query) or die(mysql_error);
}
?>
例如,循环 4 次,这意味着我有 4 个文本框。
在我的脚本中,这里没有完整编写,代码只更新数据库中的最后一个循环。
【问题讨论】: