Z
Z
zhd-dm2020-06-01 21:54:44
PHP
zhd-dm, 2020-06-01 21:54:44

How to delete an account at the request of the user?

Good afternoon!
I am writing a graduation project and I have a task: in the personal account, the user can delete his account.
I've already read enough forums and did not find a solution. There is a connection to the database, the data is entered, I tried to write different queries - it did not work out. I enclose the code:
Index.php file:

<p> Привет, <?=$_COOKIE['user']?>! </p>

          <form action="join_chat.php" method="post">
            <button class="btn btn-success" type="submit"> Чтобы войти в чат нажмите здесь </button>
          </form>
          <br>
          <form action="exit.php" method="post">
            <button class="btn btn-warning" type="submit"> Чтобы выйти нажмите здесь </button>
          </form>
          <br>
          <form action="delete_account.php" method="post">
            <button class="btn btn-danger" type="submit"> Чтобы удалить аккаунт нажмите здесь </button>
          </form>


File delete_account.php:
<?php 
  $id = filter_var(trim($_POST['id']),
  	FILTER_SANITIZE_STRING);
  $login = filter_var(trim($_POST['login']),
  	FILTER_SANITIZE_STRING);
  	$name = filter_var(trim($_POST['name']),
  	FILTER_SANITIZE_STRING);
  	$pass = filter_var(trim($_POST['pass']),
  	FILTER_SANITIZE_STRING);
  	$root_id = filter_var(trim($_POST['root_id']),
  	FILTER_SANITIZE_STRING);
  $root_name = filter_var(trim($_POST['root_name']),
  FILTER_SANITIZE_STRING);


  $mysql = new mysqli('localhost', 'root', 'root', 'diplom');
  
  
  $mysql->query("DELETE FROM `username` WHERE `id` = '$id'");
  

  $mysql->close();
  	header('Location: /');
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
part_os, 2020-06-14
@part_os

<form action="delete_account.php" method="post">
            <button class="btn btn-danger" type="submit"> Чтобы удалить аккаунт нажмите здесь </button>
          </form>

If you look at this piece, then when submitting the form, the expected $_POST['id'] is not passed. Wang need to add them to your form. Hidden input and other variables.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question