1

After entering a customer name in the form, and clicking delete, the customer and all its data should also be deleted. The form includes <form method="POST">

When I run it I get this:

PHP Notice: Undefined variable: customer_name in /banking_delete.php on line 14

which is this line:

$data = array ('customer_name' => $customer_name);

The entire code is this:

<?php
include_once 'banking_db.php';
include 'banking_display.php';
# form data
if(isset($_POST['customer_name'])){
    $customer_name = $_POST['customer_name'];
}
if(isset($customer_name)){ 
    echo $customer_name;
}
$sql = "delete from customer where customer_name = :customer_name;";
$stmt = $conn->prepare($sql);
# data stored in an associative array
$data = array ('customer_name' => $customer_name);
if($stmt->execute($data)){
$rows_affected = $stmt->rowCount();
echo "<h2>".$rows_affected." row deleted sucessfully!</h2>";
display("select customer_name as customer_name, customer_city as customer_city, customer_street as customer_street from customer;");
} 
else
{
        echo "\PDOStatement::errorInfo():\n";
        print_r($stmt->errorInfo());
}
$stmt = null;
$conn = null;
?>
New123
  • 35
  • 4
  • Does this answer your question? ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – Progman May 01 '21 at 09:31

1 Answers1

0

You forget to defined the array write this line before using the array

$data = array();
$data = array ('customer_name' => $customer_name);
Samad
  • 34
  • 1
  • 6