我的php文件存在验证问题..编码如下:
<html>
<head>
<body>
</body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Enter ID:
<input type="text" name="Delete">
<input type="submit" value="OK">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$servername="localhost";
$username="root";
$password="";
$dbname="Ystock";
$delete=$_REQUEST["Delete"];
if($delete=="")
{
echo"Please Enter a correct ID";
}
else
{
$conn=mysqli_connect($servername,$username,$password,$dbname);
if(!$conn)
{
die("Connection Failed!".mysqli_error($conn));
}
$sql="DELETE FROM total WHERE ID='$delete'";
if(mysqli_query($conn,$sql))
{
echo "Data deleted";
}
else
{
echo"Error in delete".mysqli_error($conn);
}
mysqli_close($conn);
}
}
else
{
}
?>
</body>
</head>
</html>
问题在于,当我尝试输入Id no。要删除记录虽然它不在“ID”列中,但它显示消息“数据已删除”。例如,如果我删除ID 1然后删除n显示消息“数据已删除”。但是如果我将ID 1再次删除然后它也显示消息“数据删除”..请帮帮我。
答案 0 :(得分:1)
您必须使用mysqli_affected_rows函数来检查查询是否确实删除了一行