目标
我正在尝试创建一个页面以从我的数据库中删除记录。该页面将由一个在页面加载时自行填充的页面组成。从 中选择一个值并单击提交按钮后,将调用一个 php 页面并显示结果php 将被加载到下面的表中。然后我可以单击位于回显值旁边的删除按钮以从数据库中删除该值
我的表格:
<!DOCTYPE HTML>
<html>
<head>
<!--Loads JQuery script-->
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<!--Gets list of item categories on page load-->
<script type="text/javascript">
$(document).ready(function(){
$("#viewsubcat").load("getcategory.php");
});
</script>
<script type="text/javascript">
$("#viewsubcatsubmit").click(function(){
var cat=$('#viewsubcat').val();
$('#deletetable').load('delsubcategory.php?cat='+cat);
});
</script>
</head>
<body>
<form style="width:500px" id="viewsubcategory" name="viewsubcategory" method="post" action="<? php echo $_SERVER['PHP_SELF'] ?>" >
<div class="inputfield">
<label for="viewsubcat">Select Category:</label>
<select style="margin-left:37px" id="viewsubcat" name="viewsubcat"></select>
</div><br />
<div class="inputfield">
<input style="margin-left:250px" type="button" id="viewsubcatsubmit" name="viewsubcatsubmit" value="Search" /></div>
</div><br />
</form>
<table id="deletetable">
</table>
</body>
</html>
PHP页面:
<?php
include("cxn.inc");
$id=$_SESSION['BizID'];
$cat=$_GET['cat'];
$viewsubcat=$cxn->prepare("SELECT * FROM `itemcat`,`itemsubcat`
WHERE `itemcat`.`CatID`=:cat AND `itemsubcat`.`ItemCat`=:cat AND `itemsubcat`.`BusinessID`=:id");
$viewsubcat->bindValue(":cat",$cat);
$viewsubcat->bindValue(":id",$id);
$viewsubcat->execute();
//echo"<table border='1'>";
echo"<tr>";
echo"<td>";
echo"Categories";
echo"</td>";
echo"<td>";
echo"SubCategories";
echo"</td>";
echo"<td>";
echo"Action";
echo"</td>";
echo"</tr>";
while($getsubcat=$viewsubcat->fetch(PDO::FETCH_ASSOC))
{
$cat=$getsubcat['ItemCat'];
$subcat=$getsubcat['ItemSubCat'];
$subcatid=$getsubcat['SubCatID'];
echo"<tr>";
echo"<td>";
echo"$cat";
echo"</td>";
echo"<td>";
echo"$subcat";
echo"</td>";
echo"<td>";
echo"<form id='delsubcategory' name='delsubcategory' method='POST' action='delsubcategory.php'>";
echo"<input type='hidden' id='delsubcatid' name='delsubcatid' value='$subcatid' />";
echo"<input type='submit' id='delsubcatsubmit' name='delsubcatsubmit' value='Delete' />";
echo"</form>";
echo"</td>";
echo"</tr>";
}
//echo"</table>";
?>
问题:
按下按钮后 HTML 表未加载。当我将表单的操作更改为“delsubcategory.php”并且按钮类型 =“submit”时,Php 页面正在工作,因此问题出在 html 上。
希望对此事有任何见解