forked from sajjadsaleem341/Plant-Nest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_profile.php
41 lines (34 loc) · 1.15 KB
/
delete_profile.php
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
<?php
include "config.php"; // Include your database connection file
session_start(); // Start the session
// Check if 'id' is set in the URL
if (isset($_GET['id']) && !empty($_GET['id'])) {
$user_id = intval($_GET['id']); // Convert the ID to an integer for safety
// Prepare SQL query to delete the user
$sql = "DELETE FROM users WHERE id = ?";
// Prepare the statement
if ($stmt = $con->prepare($sql)) {
// Bind parameters
$stmt->bind_param("i", $user_id);
// Execute the statement
if ($stmt->execute()) {
// Success: delete session variables and redirect
unset($_SESSION['USER_LOGIN']);
unset($_SESSION['USER_ID']);
unset($_SESSION['USER_NAME']);
// Redirect to index page
header("Location: Index.php");
exit();
} else {
echo "Error deleting user: " . $stmt->error;
}
// Close the statement
$stmt->close();
} else {
echo "Error preparing statement: " . $con->error;
}
// Close the connection
$con->close();
} else {
echo "No user ID provided.";
}