Get $email from row depending on the id

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.


(Τhe only thing that interests me at the moment is the solution of the problem and not the security problems that exist)


$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";
    $subject = "DELETED";
    $message = "DELETED REQUEST";
    $sender = "From:";
    $email = ?;
    mail($email, $subject, $message, $sender);

  } else {
    echo "Error cancelled record: " . $con->error;


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.