For some time now I've been trying to develop a system of account deletion on the part of the user, like what we witnessed on facebook and twitter where in the user settings, the same can opt can delete your account. But my temptations were frustrated.
So I decided to come here, as always. Any step-by-step tutorials?
ThisisthephpcodeI'vetried(closecontain.php):
$id = $_SESSION['id'];
if ($usuario) {
if (isset($_POST['sim'])) {
header("location: /configuracoes");
}
if (isset($_POST['nao'])) {
$fecharconta = mysql_query("UPDATE usuario SET 'fechada'='$fechada' WHERE id='$id'");
echo "Sua conta foi fechada";
session_destroy();
}
}
else {
die("Você não está logado!");
}
and this is HTML:
<div id="conteudo">
<div class="conteudo-fundo">
<form action="fecharconta.php" method="POST">
Você tem certeza de que pretende fechar sua conta?<br>
<input type="submit" name="no" value="Não, me leve de volta">
<input type="submit" name="yes" value="Sim, eu tenho certeza">
</form>
</div>
</div>
And highlighted in red is the column I created in the database to check if the user is active I inactive.
Finally,aftertryingandgettingcommunitytips,Iwasabletosolvetheproblem.
Iwasabletosolvetheproblem,IwillmakeavailableherethecodethatIusedandthesteps.
Thisisthehtmlcodethathasanactionpointingtodisable-account.php
<div id="conteudo">
<div class="conteudo-fundo">
<form action="view/desativar-conta.php" method="POST">
Você tem certeza de que pretende fechar sua conta?<br>
<input type="submit" name="no" value="Não, me leve de volta">
<input type="submit" name="yes" value="Sim, eu tenho certeza">
</form>
</div>
</div>
This is the code for the disable-account.php
<?php
include_once("../php/dados.php");
$id = $_SESSION['id'];
$sql = mysqli_query("SELECT * FROM usuario WHERE email='$login_cookie'");
$dado = mysqli_fetch_assoc($sql);
session_start();
if ($id) {
if (isset($_POST['no'])) {
header("location: /configuracoes");
}
if (isset($_POST['yes'])) {
$desativar = mysql_query ("UPDATE usuario SET desativada='yes' WHERE id='$id'");
echo "Sua conta foi desativada!";
session_destroy();
}
}
else{
die(header("location: ./../"));
}
?>
When the user clicks on the input value, "Yes, I'm sure" will automatically change the value of the disabled column in the database.
I also added the following php code to the login php: disabled = 'no' , which only allows the user to login when the disabled column is > 'no' .
The code inside this login.php , within the variable that selects the data from the database is as follows:
SELECT * FROM user WHERE email = '$ email' AND password = '$ password' AND disabled = 'no'
And in the photo below, highlighted in orange is the disabled column