-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
92 lines (78 loc) · 3.16 KB
/
edit.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
// set page headers
$page_title = "Edit User";
include_once "header.php";
// include database and object user file
include_once 'classes/database.php';
include_once 'classes/user.php';
include_once 'initial.php';
// isset() is a PHP function used to verify if ID is there or not
$id = isset($_GET['id']) ? $_GET['id'] : die('ERROR! ID not found!');
// instantiate user object
$user = new User($db);
$user->id = $id;
$user->getUser();
// show page header
echo "<div class='page-header d-flex justify-content-between'>";
echo "<h2>{$page_title}</h2>";
// read user form and buttons
echo '<form action="edit.php?id='. $id . '" method="post">';
/*<form action='edit.php?id=<?php echo $id; ?>' method='post'>*/
echo "<div class='form'>";
echo "<a href='index.php' class='btn btn-light left-margin'>";
echo "<i class=\"fa fa-arrow-circle-left\" aria-hidden=\"true\"></i></span> Back ";
echo "</a>";
echo '<button type="submit" class="btn btn-warning bg-gradient-warning text-white left-margin">';
echo '<i class="fa fa-check-circle" aria-hidden="true"></i></span> Save';
echo '</button>';
echo '<button type="submit" class="btn btn-warning bg-gradient-warning text-white">';
echo '<i class="fa fa-check-circle" aria-hidden="true"></i></span> Save And Continue Edit';
echo '</button>';
echo "</div></div><!-- .page-header -->";
echo '<hr class="mt-0" style="border-width:3px;">';
// check if the form is submitted
if($_POST)
{
// set user property values
$user->first_name = htmlentities(trim($_POST['first_name']));
$user->last_name = htmlentities(trim($_POST['last_name']));
$user->email = htmlentities(trim($_POST['email']));
// Edit user
if($user->update()){
echo "<div class=\"alert alert-success alert-dismissable\">";
echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">
×
</button>";
echo "Success! User is edited.";
echo "</div>";
}
// if unable to edit user
else{
echo "<div class=\"alert alert-danger alert-dismissable\">";
echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">
×
</button>";
echo "Error! Unable to edit user.";
echo "</div>";
}
}
?>
<div class="alert alert-info mb-0" role="alert">User information</div>
<table class='table table-hover table-responsive table-bordered' style='display: table;'>
<tr>
<td>First Name</td>
<td><input type='text' name='first_name' value='<?php echo $user->first_name;?>' class='form-control' placeholder="Enter First Name" required></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type='text' name='last_name' value='<?php echo $user->last_name;?>' class='form-control' placeholder="Enter Last Name" required></td>
</tr>
<tr>
<td>Email Address</td>
<td><input type='email' name='email' value='<?php echo $user->email;?>' class='form-control' placeholder="Enter Email Address" required></td>
</tr>
</table>
</form>
<?php
include_once "footer.php";
?>