该表单应该通过输入客户 ID 从客户表中删除客户行,但它没有做它应该做的,我不知道为什么!当我执行 PHP 文件时,我没有收到任何错误。
我知道它应该可以工作,因为我使用相同的代码从员工表中删除信息并且工作正常。
删除客户表单
<!DOCTYPE html>
<head>
<?php include 'project_header.php'; ?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form action="customer_delete.php" method="post">
<h2> Delete a Customer</h2>
<p>Please Enter Customer Information:</p>
Customer ID: <input type="text" ID="Customer_ID"/><br>
<input type="submit" value= "Delete"/><input type="reset"/>
</form>
</body>
<?php include 'project_footer.php'; ?>
</html>
删除客户 PHP
<!DOCTYPE html>
<html>
<?php include 'project_header.php'; ?>
<body>
<?php
include_once 'db.php';
include_once 'display.php';
#form data
$Customer_ID=$_POST['Customer_ID'];
$sql = "delete from CUSTOMERS where Customer_ID = :Customer_ID;";
$stmt = $conn->prepare($sql);
# data stored in an associative array
$data = array( 'Customer_ID' => $Customer_ID);
if($stmt->execute($data)){
$rows_affected = $stmt->rowCount();
echo "<h2>".$rows_affected." row deleted sucessfully!</h2>";
display("select Customer_ID as Customer ID FROM CUSTOMERS;");
}
else
{
echo "\nPDOStatement::errorInfo():\n";
print_r($stmt->errorInfo());
}
$stmt = null;
$conn = null;
?>
</body>
<?php include 'project_footer.php'; ?>
</html>
name
您的文本框中似乎没有属性。这就是 PHP 获取POST
信息的方式,因此如果没有设置,您将无法访问用户输入的内容。只需将属性从 更改ID
为name
(或仅在需要时添加name
属性id
),就可以解决问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句