<td>
<form action="del.php" method="POST">
<?php foreach($jk as $item) {
echo"<input type='hidden' name='id' value='".$item['emc_id']."'>";
}
?>
<input type="submit" name="downld" value="DELETE" >
</form>
</td>如您所见,我正在使用del.php中隐藏的方式传递一个值。我得到了一个4。我的数据库中有4个数据,但是当我单击rowid-1、rowid-2和任何其他id时,我总是得到一个id-4。我希望每当我点击删除按钮,相应的id应该被删除。
发布于 2013-06-14 10:15:49
你到底想达到什么目的?您想一次删除一行还是多行?您现在要做的是动态地创建隐藏框,但是隐藏字段的名称是相同的,所以当浏览器呈现时,它将创建以下四个文本框:
<input type="hidden" name="id" value="1" />
<input type="hidden" name="id" value="2" />
<input type="hidden" name="id" value="3" />
<input type="hidden" name="id" value="4" />现在,当您发布表单时,您将得到最后一个值。因此,您将始终得到4。如果您试图删除单个记录,然后使用paw建议的方法。如果要删除多条记录,请在每行的下面使用复选框,并确保对复选框名称(如name="foo[]“)使用数组(例如符号)。
发布于 2013-08-02 07:08:13
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel">
<html>
<head>
WELCOME <?=$_SESSION['user']?></br>
<a href="logout.php" >log-out</a></br>
<title> emc promo 1</title>
<meta http-equiv="Content-type" content="text/html;charset=utf-8" />
</head>
<body>
<b>the total no rows are :</b><?=$g?>
<table cellpadding="5" border="1" style="width:450px;"><tr>
<?php for ($i=0; $i < count($colnames); $i++) { ?>
<td><?=$colnames[$i]?></td>
<?php }?>
<td>DELETE</td>
<td>EDIT</td>
</tr>
<?php for ($i=0; $i < count($jk); $i++) { ?>
<tr>
<?php for ($ii=0; $ii < count($colnames); $ii++) {?>
<td><?=$jk[$i][$colnames[$ii]]?></td>
<?php }?>
<td><form action="del.php" method="POST">
<input type='hidden' name='id' value= <?php echo $jk[$i];?>>
<input type="submit" name="downld" value="DELETE" >
</form></td>
<td><form action="edit.php" method="POST">
<input type="hidden" name="id1" value="<?=$jk['$i'];?>">
<input type="submit" name="downld" value="UPDATE " >
</form></td>
</tr>
<?php } ?>
</table>
</body>
</html>我得到了答案,现在我正在传递所有的列值,以便在删除和编辑时进行检查。
发布于 2013-06-14 10:05:00
您应该在您的行中附加一个id,如下所示:在foreach中
echo "<a href="delete.php?id=". $row['id']>Delete</a>"
每当用户单击链接,删除,id将被传递到一个php脚本中,在那里,您将$_GET,id传递,并有一个使用id的delete query,我希望这会有所帮助。
https://stackoverflow.com/questions/17105907
复制相似问题