-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_profile.php
More file actions
47 lines (37 loc) · 1.16 KB
/
delete_profile.php
File metadata and controls
47 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
$servername = "localhost";
$username = "root"; // Replace with your database username
$password = ""; // Replace with your database password
$dbname = "vehicle_auction";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
session_start();
$response = array();
if (isset($_POST['userId'])) {
$userId = $_POST['userId'];
// Delete the user from the database
$query = "DELETE FROM users WHERE id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("i", $userId);
if ($stmt->execute()) {
$response['success'] = true;
// Destroy the session to log out the user
session_destroy();
} else {
$response['success'] = false;
$response['error'] = $stmt->error;
}
$stmt->close();
} else {
$response['success'] = false;
$response['error'] = 'User ID not provided';
}
// Set the content type to JSON and return the response
header('Content-Type: application/json');
echo json_encode($response);
$conn->close();
?>