-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.php
44 lines (39 loc) · 1.46 KB
/
delete.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
42
43
44
<?php
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Connect to the database (replace dbname, username, password with actual values)
$mysqli = new mysqli("localhost", "root", "", "test");
// Check connection
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
// Retrieve form data
$userId = $_POST['id'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
// Prepare and execute a query to update the user's data
$sql = " users SET name=?, email=?, phone=?, address=? WHERE id=?";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("ssssi", $name, $email, $phone, $address, $userId);
$stmt->execute();
// Check if the update was successful
if ($stmt->affected_rows > 0) {
// Redirect the user back to the index page with a success message
header("Location: dispaly_users.php?message=success");
exit();
} else {
// Redirect the user back to the edit page with an error message
header("Location: delete.php?id=$userId&message=error");
exit();
}
// Close the prepared statement and database connection
$stmt->close();
$mysqli->close();
} else {
// If the form is not submitted, redirect the user back to the edit page
header("Location: edit.php?id=$userId");
exit();
}
?>