Hi All,
Would appreciate some pointers in how I can echo out the "name" field in my delete confirmation. I understand the process on echoing the $name variable after the message but haven't been able to figure out how to define the variable that holds the name field value upon deletion.
Do I need to setup another mysql query to get the value from the name field in a assoc array?
Any help or pointers for better understanding would be very much appreciated.
Thanks!
Code:
<?php
require("database.php");
$id = 0;
if (!empty($_GET["id"])) {
$id = $_REQUEST["id"];
}
if (!empty($_POST)) {
// Keep track of post values
$id = $_POST["id"];
$name = $_POST["name"];
// Delete data
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "DELETE FROM customers WHERE id = ?, name = ?";
$stmt = $pdo->prepare($query);
$stmt->bindValue(1, $id, PDO::PARAM_INT);
$stmt->bindValue(2, $name, PDO::PARAM_STR);
$stmt->execute();
Database::disconnect();
header("Location: index.php");
}
?>
HTML:
<form class="form-horizontal" action="delete.php" method="post">
<input type="hidden" name="id" value="<?php echo $name; ?>" />
<p class="alert alert-error">Are you sure you want to delete?</p>
<div class="form-actions">
<button type="submit" class="btn btn-danger">Yes</button>
<a class="btn" href="index.php">No</a>
</div>
</form>