Let's say I have an user registered on my website and they now want to delete the account.
I've a query to do that but every time the user uses this functionality the code deletes all users.
Here is my code:
<?php
// starts session
session_start();
// set values
$DB_SERVER = 'localhost';
$DB_USERNAME = 'root';
$DB_PASSWORD = '';
$DB_NAME = 'acoolname';
// creates a new connection to the database
$conn = new mysqli($DB_SERVER, $DB_USERNAME, $DB_PASSWORD, $DB_NAME);
// checks connection
if ($conn->connect_error) {
die("ERRO: Falha ao conectar. " . $conn->connect_error);
}
// query to delete the user
$sql = "DELETE FROM users WHERE id = id";
// logout user
if ($conn->query($sql) === true) {
header("location: logout.php");
}else {
echo "ERRO: Falha ao conectar. " . $conn->error;
}
// close connection
$conn->close();
?>