-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.php
86 lines (72 loc) · 2.89 KB
/
create.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
<?php
// set page headers
$page_title = "Create User";
include_once "header.php";
// get database connection
include_once 'classes/database.php';
include_once 'initial.php';
// 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="create.php" role="form" 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">';
echo '<i class="fa fa-check-circle" aria-hidden="true"></i></span> Save';
echo '</button>';
echo "</div></div><!-- .page-header -->";
echo '<hr class="mt-0" style="border-width:3px;">';
// check if the form is submitted
if ($_POST){
// instantiate user object
include_once 'classes/user.php';
$user = new User($db);
// 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']));
$timestamp = date('Y-m-d H:i:s');
$user->create_date = $timestamp;
$user->update_date = $timestamp;
// if the user able to create
if($user->create()){
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 created.";
echo "</div>";
}
// if the user unable to create
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 create 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' class='form-control' placeholder="Enter First Name" required></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type='text' name='last_name' class='form-control' placeholder="Enter Last Name" required></td>
</tr>
<tr>
<td>Email Address</td>
<td><input type='email' name='email' class='form-control' placeholder="Enter Email Address " required></td>
</tr>
</table>
</form>
<?php
include_once "footer.php";
?>