-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregistration.php
202 lines (128 loc) · 4.08 KB
/
registration.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
session_start();
?>
<?php
include_once 'controller/connection.php';
include_once 'controller/user.php';
$_User = new User();
if(isset($_POST['submit'])){
$data_missing = array();
if(empty($_POST['F_Name'])){
$data_missing[] = ' First Name ';
} else {
$f_name = trim($_POST['F_Name']);
}
if(empty($_POST['L_Name'])){
$data_missing[] = ' Last Name ';
} else{
$l_name = trim($_POST['L_Name']);
}
if(empty($_POST['Username'])){
$data_missing[] = ' Username ';
} else{
$username = trim($_POST['Username']);
}
if(empty($_POST['Email'])){
$data_missing[] = ' Email ';
} else{
$email = trim($_POST['Email']);
}
if(empty($_POST['Password'])){
$data_missing[] = ' Password ';
} else{
$password = trim($_POST['Password']);
}
if(empty($_POST['address'])){
$data_missing[] = ' address ';
} else{
$address = trim($_POST['address']);
}
if(empty($_POST['role_id'])){
$data_missing[] = ' Role ';
} else{
$role_id = trim($_POST['role_id']);
}
if(empty($data_missing)){
$connection = mysqli_connect("localhost","root","","hstore");
$query = "INSERT INTO users(fname, lname, address, email, username,
password, role_id) VALUES ('$f_name','$l_name','$address','$email','$username','$password','$role_id')";
$result = mysqli_query($connection, $query);
print_r($result);
//test if there was a query error
if ($result)
//success
echo "successful";
else
{
die("Database query not working. " . mysqli_error($connection));
}
$id = mysqli_insert_id($connection);
} else {
echo 'You need to enter the following data<br />';
foreach($data_missing as $missing){
echo "$missing<br />";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Registration</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="resources/js/jquery.min.js"></script>
<link rel="stylesheet" href="resources/css/master.css">
</head>
<body>
<header>
<?php include_once 'template/header.php'; ?>
</header>
<div class="container">
<form name="regform" action="" method="POST" >
<h3>Registration </h3>
<table class="table table-condensed">
<tr>
<td>First Name :</td><td><input type="text" name="F_Name" placeholder="First Name" class="form-control"></td>
</tr>
<tr>
<tr>
<td>Last Name:</td><td><input type="text" name="L_Name" placeholder="Last Name" class="form-control"></td>
</tr>
<td>Username :</td><td><input type="text" name="Username" placeholder="Username" class="form-control"></td>
</tr>
<tr>
<td>Email :</td><td><input type="email" name="Email" placeholder="Email" class="form-control"></td>
</tr>
<tr>
<td>Password :</td><td><input type="password" name="Password" placeholder="Password" class="form-control"></td>
</tr>
<tr>
<td>Address. :</td><td><input type="text" name="address" placeholder="Address" class="form-control"></td>
</tr>
<tr>
<td>Role. :</td><td><?php
// this block of code prints the list box of Positions with current assigned Positions
$var = '<select name="role_id" class="form-control" multiple>';
$Result = $_User->getAllRole();
while($Role=mysqli_fetch_array($Result,MYSQLI_ASSOC)) {
$var = $var. '<option value="'.$Role['id'].'"';
$var = $var.'>'.$Role['r_name'].'</option>';
}
$var = $var.'</select>';
echo $var;
?>
</td>
</tr>
<tr>
<td></td><td><input type="submit" name="submit" value="Register" class="btn btn-primary btn-block" ></td>
</tr>
</table>
</form>
<div class="modal-footer text-right">
<a href="login.php">Already have account? Login!</a> <br>
</div>
<?php include_once 'template/footer.php'; ?>
</div>
</body>