User deletion system by the user himself

Asked

Viewed 69 times

1

For some time I’ve been trying to develop a system of account deletion by the user, like what we see on facebook and twitter where in the user’s settings, the same can choose to delete your account. But my attempts were thwarted.

So I decided to come here as always. Some tutorial step by step?

This is the php code I tried (close.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.

inserir a descrição da imagem aqui

Finally, after trying so hard and with tips from the community, I managed to solve the problem.

I managed to solve the problem, I will make available here the code I used and the steps.

This is the html code that has an action pointing to deactivate.php account

<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 file code deactivate.php account

<?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 with value: "Yes, I’m sure", it automatically changes the value of the column deactivated in the database.

I also added the following to the php login code: deactivated = 'no', which only allows the user to login when the column deactivated is 'in the'.

The code within that login.php, within the variable that selects the database data was the following:

SELECT * FROM user WHERE email='$email' AND password='$password' AND disabled='no'

And in the photo below, highlighted in orange is the column deactivated

inserir a descrição da imagem aqui

  • 1

    Post what tried to friend so that we can help, basically it is only by clicking the button run a DELETE in the database erasing the user. Or an UPDATE changing a binary column in the user record showing whether or not it is active

  • It seems to me that the php check is reversed... You check if there is a variable of type POST['yes'] that does not delete... That’s right?

  • I made the change by correcting POST['yes'] for POST['no'] and POST['nao'] for POST['yes']. But the code body of html does not appear when I enter the close php account. in the same file html, which is weird, I don’t understand why it’s missing.

  • It is better to leave the code in another file, because otherwise the code runs as soon as it loads the form and it may happen that not to appear.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.