Reputation: 35
The form is supposed to delete a customer row from the customer table by entering customer ID, but it is not doing what it is supposed to, I dont know why! When I executed the PHP file I dont get any errors.
I know it should work because I used the same code to delete information from the employee table and it worked fine.
Delete Customer Form
<!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>
Delete Customer 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>
Upvotes: 0
Views: 380
Reputation: 64
Customer ID: <input type="text" ID="Customer_ID"/>
In this line you need to add the "name" attribute, and that should fix the issue.
What you should do is:
Customer ID: <input type="text" ID="Customer_ID" name="Customer_ID"/>
Greetings!
Upvotes: 2
Reputation: 397
It seems that there is no name
attribute on your text box. This is how PHP gets the POST
information, so without it being set, you can't access what the user inputted. Simply change the attribute from ID
to name
(or just add the name
attribute if id
is needed) and that should fix the issue.
Upvotes: 2