当前位置: 代码迷 >> PHP >> php批改单条数据,结果全部数据都被修改了
  详细解决方案

php批改单条数据,结果全部数据都被修改了

热度:235   发布时间:2016-04-28 18:49:11.0
php修改单条数据,结果全部数据都被修改了
<form  id="frm" name="frm" method="POST" action="" >
<p legend align="center"><b>浏览检查信息</b></legend></p>
<table border="1" width="100%" bgcolor="#CAFFFF" id="table1" height="20%"  cellspacing="0" bordercolor="#808080">
<tr  height="36" >
<td width="101" align="center">姓名</td>
<td width="33" align="center">性别</td>
<td width="106" align="center">检查时间</td>
</tr>
<?php 
$result=$connection->query("select * from t_user ");
  while($rs=$result->fetch_row()) {
  
  ?>
      <tr  height="36" >
<td width="101"><?php echo $rs[1]?> </td>
<td width="33"><?php echo $rs[2]?> </td>
<td width="106"><?php echo date("Y-m-d")?> </td>
    <td width="72" align="center" ><input name="button" type="button" onClick="location.href='?type=modify&id=<?php echo $rs[0]?>'" value="修改" /> <input name="button2" type="button" onClick="location.href='?type=del&id=<?php echo $rs[0]?>'" value="删除"  /></td>
      </tr><?php
  }?>
  </table>
</form>
<?php
    if($_GET["type"]=="modify"){

$id=$_GET['id'];
if($_POST["submit3"])
{
$result=$connection->query("update t_user set f_username='$a', f_sex='$b',f_age='$c',f_CT='$d',f_zaoyingji='$f',f_buwei='$g',f_HU='$h',f_jishu='$i',f_xiaoaguo='$j',f_qianming='$k',f_yanchi_time='$l',f_chufa_time='$m'");
if($result) {
   echo"<script language=javascript>alert('数据修改成功!');window.location='index.php'</script>";
}
else {
echo "数据修改失败";
}
}
$result=$connection->query("select * from t_user where id=$id ");
  while ($rws=$result->fetch_row()) {
  ?>
 <form id="form1" name="form1" method="POST" action="" >
 <p align="center"><b>修改检查信息</b></p>
<table border="1" width="100%" bgcolor="#CAFFFF" id="table2" height="20%"  cellspacing="0" bordercolor="#808080">
<tr>
  <td width="94" align="center"><input name="a" type="text" id="a" value="<?php echo $rws[1]?>" style="width:94; height:38;font-size:20pt" size="20" /></td>
<td width="40" align="center"><input name="b" type="text" id="b" value="<?php echo $rws[2]?>" style="width:40; height:38;font-size:20pt" size="20" /></td>
  <td width="121" align="center"><?php echo date("Y-m-d")?></td>
      </tr><?php
}
?>
</table>
<tr>
  <p align="center">
<input type="submit" value="修改" name="submit3" style="font-size: 18pt; letter-spacing:2"> 
<input type="reset" value="重置" name="reset" style="font-size: 18pt; letter-spacing:2">
<input  type="button"  name="button" onClick="location.href='?type=del&id=<?php echo $rs[0]?>'" style="font-size: 18pt; letter-spacing:2" value="删除" >
  </p>
</tr>
</form><?php
}
?>
<?php
if($_GET["type"]=="del"){
$id=$_GET["id"];
$result=$connection->query("delete from t_user where id in ($id)");
echo "<script language=javascript>alert('删除成功!');window.location='index.php'</script>";
}
?>
------解决方案--------------------
更新時需要加條件 where id='$id'

$result=$connection->query("update t_user set f_username='$a', f_sex='$b',f_age='$c',f_CT='$d',f_zaoyingji='$f',f_buwei='$g',f_HU='$h',f_jishu='$i',f_xiaoaguo='$j',f_qianming='$k',f_yanchi_time='$l',f_chufa_time='$m' where id='$id'");
  相关解决方案