I want every time I click the delete button, this row is deleted and an email is automatically sent to the user that it has been deleted.
I have a table with users and in every row there is a “DELETE” btn. When click “DELETE” btn run delete.php.
The code in delete.php Delete successfully the row but the problem is that I dont no how can get user’s email for the clicked row.
$email=?
(Τhe only thing that interests me at the moment is the solution of the problem and not the security problems that exist)
delete.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "userform";
// Create connection
$con = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
$sql = "SELECT name, email, code, status, lname, checkin, checkout, mnumber, totalprice, rescode FROM usertable";
$result = $con->query($sql);
$email = "SELECT email FROM usertable WHERE id='" . $_GET['id'] . "'";
$sql = "DELETE FROM usertable WHERE id='" . $_GET['id'] . "'";
if ($con->query($sql) === TRUE) {
echo "Deleted successfully";
// SEND CANCELLATION EMAIL
$subject = "DELETED";
$message = "DELETED REQUEST";
$sender = "From: myemail@gmail.com";
$email = ?;
mail($email, $subject, $message, $sender);
} else {
echo "Error cancelled record: " . $con->error;
}
$con->close();
?>```