I am trying to solve an issue I am facing. I want to delete a logged in user from a MySql database after they click a button.
The code I have named as changepw.php
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "loginsystem";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$uid =$_REQUEST['user_uid'];
// sql to delete a record
$sql = "DELETE FROM users WHERE user_uid='$uid'";
if ($conn->query($sql) === TRUE) {
    echo "Record deleted successfully";
} else {
    echo "Error deleting record: " . $conn->error;
}
$conn->close();
?> 
It refers to this line:
$uid =$_REQUEST['user_uid'];
My login.php file looks like this:
<?php
session_start();
#first if
if (isset($_POST['submit'])) {
    include 'dbh.inc.php';
    $uid = mysqli_real_escape_string( $conn , $_POST['uid'] );
    $pwd = mysqli_real_escape_string( $conn , $_POST['pwd'] );
    //Error handerlers
    //Check if this input are empty
    #second if
    if (empty($uid) || empty($pwd)) {
        header("Location: ../index.php?login=empty");
        exit();
    }/*second else*/ else {
        $sql = "SELECT * FROM users WHERE user_uid='$uid' OR user_email='$uid'";
        $result = mysqli_query($conn,$sql);
        $resultCheck = mysqli_num_rows($result);
        #third if
        if ($resultCheck < 1) {
            header("Location: ../index.php?login=error");
            exit();
        }/*third else*/ else {
            #forth if
            if ($row = mysqli_fetch_assoc($result)) {
                //de-hashing the password
                $hashedPwdCheck = password_verify($pwd , $row['user_pwd']);
                #fifth if
                if ($hashedPwdCheck == false) {
                    header("Location: ../index.php?login=error");
                    exit();
                } /*fifth else*/ elseif ($hashedPwdCheck == true) {
                    //Log in the user here
                    $_SESSION['u_id'] = $row['user_id'];
                    $_SESSION['u_first'] = $row['user_first'];
                    $_SESSION['u_last'] = $row['user_last'];
                    $_SESSION['u_email'] = $row['user_email'];
                    $_SESSION['u_uid'] = $row['user_uid'];
                    #might be not necessary
                    $email = $_SESSION['user_email'];
                    header("Location: ../index.php?login=success");
                    exit();
                }
            }
        }
    }
}/*first else*/ else {
    header("Location: ../index.php?login=error");
    exit();
}
Code where the button is located index.php
<?php
    include 'header.php';
?>
<section class="main-container">
    <div class="main-wrapper">
        <h2>About</h2>
        <?php
            if (isset($_SESSION['u_id'])) {
                echo '
                <form action="includes/changepw.php" method="POST">
                            <button type="submit" name="submit">Delete User</button>
                </form>
                    ';
            }
        ?>  
    </div>
</section>
<?php
    include 'footer.php';
?>
I would really appreciate some help as I am not sure how to solve this.
Thanks in advance!

 
     
    