User accesses the logged in page:
<?php
session_start();
echo 'Bem vindo, '.$_SESSION['username'];
?>
<br /><a href='logout.php'>Logout</a>
I want him to push a button or link and delete his own account (without typing anything).
<?php
if(isset($_POST["button"])){
$hostname='localhost';
$username='root';
$password='';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=projeto",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$del = "DELETE FROM tbl_users WHERE id =".$_SESSION['id'];
if ($dbh->query($sql)) {
echo "<script type= 'text/javascript'>alert('Conta deletada com sucesso'); </script>";
}
else{
echo "<script type= 'text/javascript'>alert('Falha');</script>";
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
How do I do it?