我似乎无法更新除第一个记录以外的任何记录。 我不知道如何修改任何显示的记录。使用WHILE循环更新回显数据。只更新一条记录
<?php
if(isset($_POST["action"]) == "update")
{
$id = $_POST['m_id'][0];
$type = $_POST['type'][0];
// if I echo $id & $type, it only gives me the first record.**
mysql_query("
UPDATE membership_type
SET mt_type ='$type'
WHERE mt_id = '$id'"
);
}
?>
ALl这是在相同的PHP页面。
<form name=form action='' method='post'>
<?php
$result=mysql_query("SELECT * FROM membership_type;");
while($rows=mysql_fetch_array($result))
{ ?>
<input size=35 class=textField type=text name='type[]' value='<?php echo $rows['mt_type']; ?>'>
<input type=hidden name='m_id[]' value="<?php echo $rows['mt_id']; ?>">
<input type=submit value="Update">
<?php
}
?>
如何通过点击更新按钮来编辑任何显示的记录?
不要使用的mysql_query,它弃用。你的代码也打开sql注入。 – Jonast92 2013-04-20 03:17:10