當我點擊提交按鈕,所選行被成功刪除,但它也顯示了以下錯誤:爲什麼我得到mysql_fetch_assoc()錯誤?
Warning: mysql_fetch_assoc().....
這裏是我的代碼:
<html>
<head>
<script type="text/javascript" language="javascript">
function checkAll(formname, checktoggle)
{
var checkboxes = new Array();
checkboxes = document.forms[formname].getElementsByTagName("input");
for (var i=0; i<checkboxes.length; i++) {
if (checkboxes[i].type == "checkbox") {
checkboxes[i].checked = checktoggle;
}
}
}
// For Delete Button
</script>
</head>
<body bgcolor='lightgray'>
<a onclick="checkAll('myform',true);" href="#">check all</a>
<br>
<a onclick="checkAll('myform',false);" href="#">uncheck all</a>
<?php
if(isset($_POST['delete']))
{
$delete_id = $_POST['chk'];
$id = count($delete_id);
if(count($id) > 0)
{
foreach ($delete_id as $id_d)
{
$sql = "DELETE FROM pm WHERE pm_id='$id_d'";
$delete = mysql_query($sql);
}
}
if($delete)
{
echo $id." Records deleted Successfully.";
}
}
?>
<?php
echo "<form name='myform' method='post' action='delete.php'>";
echo "<table border='1'>";
while($rows=mysql_fetch_assoc($sql))
{
echo "<tr><td><input type='checkbox' name='chk[]' value='$rows[pm_id]' /></td><td></td><td>$rows[subject]</td></tr>";
}
echo "</table>";
echo "<p><input id='delete' type='submit' class='button' name='delete' value='Delete Selected Items'/></p>";
echo "</form>";
?>
</body>
</html>
閱讀*相關*問題第一。 –
您的$ sql的定義在哪裏? –
你想用這個代碼做什麼!? –