我正在尝试使用PHP从MySQL中删除记录。 我需要在我的代码中添加什么,以便首先进行删除确认。 因为在我的当前代码中,它会自动删除与pnum输入相对应的记录。
<html>
<style>
input { font-size: 16px;}
</style>
<?php include('header.php'); ?>
<div id="main_content">
</div>
<?php include('footer.php'); ?>
<head>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="DeletebyPnumIn.php" method="post">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="9" style="background:#9ACD32; color:white; border:white 1px solid; text-align: center"><strong><font size="3">Delete In-patient</strong></td>
</tr>
<td><font size="3">Patient #:</td>
<td></td>
<td><input type="text" name="pnum" value="" maxlength="15" /><br/></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Delete" /></td>
</form>
</tr>
</table>
<body>
</body>
</html>
这里是表单操作:
<html>
<style>
input { font-size: 16px;}
</style>
<?php include('header.php'); ?>
<div id="main_content">
</div>
<?php include('footer.php'); ?>
<head>
<?php
$con = mysql_connect("localhost","root","nitoryolai123$%^");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hospital", $con);
mysql_query("DELETE FROM t2 WHERE PNUM='{$_POST["pnum"]}'") ;
mysql_close($con);
echo "<script>alert('Record successfully deleted!')</script>";
?>
请帮忙。
$pnum=(int)$_POST['pnum']
进行过滤以确保其是一个数字(如果这是您想要的)。 - JAL