【发布时间】:2013-04-20 02:55:37
【问题描述】:
我似乎无法更新除第一条记录之外的任何记录。 我不确定如何修改任何显示的记录。
<?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'"
);
}
?>
所有这些都在同一个 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 注入开放。
标签: php mysql forms post while-loop