-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_user_form.php
61 lines (51 loc) · 1.99 KB
/
update_user_form.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
include('./controller/userscontr.php');
include('./view/usersview.php');
// update_user_form.php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_user'])) {
// Form is submitted, process the update
$userId = $_POST['id'];
$first_name = $_POST['f_name'];
$last_name = $_POST['l_name'];
$age = $_POST['age'];
$usersContr = new UsersContr();
$usersContr->updateUser($userId, $first_name, $last_name, $age);
// Redirect to index.php or any other page after updating
header("Location: index.php");
exit();
} else {
// Display the update form
// Fetch user details based on the id
if (isset($_GET['id'])) {
$userId = $_GET['id'];
$usersView = new UsersView();
$userDetails = $usersView->getUserDetails($userId);
if ($userDetails) {
// Display the update form
?>
<!-- Your HTML form for updating user -->
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $userDetails['id']; ?>">
<div class="form-group">
<label for="f_name">First Name</label>
<input type="text" name="f_name" class="form-control" value="<?php echo $userDetails['first_name']; ?>">
</div>
<div class="form-group">
<label for="l_name">Last Name</label>
<input type="text" name="l_name" class="form-control" value="<?php echo $userDetails['last_name']; ?>">
</div>
<div class="form-group">
<label for="age">Age</label>
<input type="text" name="age" class="form-control" value="<?php echo $userDetails['age']; ?>">
</div>
<input type="submit" class="btn btn-success" name="update_user" value="UPDATE">
</form>
<?php
} else {
echo "User not found.";
}
} else {
echo "Invalid request.";
}
}
?>