-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewUser.php
More file actions
48 lines (36 loc) · 1.4 KB
/
Copy pathnewUser.php
File metadata and controls
48 lines (36 loc) · 1.4 KB
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
<?php
require_once ('StartSession.php');
// Test data here, but you would replace with your User Registration Form data processing
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$eMail = $_POST['email']; // email is used as username
$password = $_POST['password'];
// Role will be defaulted in DB, do not set here
$hashedPw = password_hash($password, PASSWORD_DEFAULT);
// echo "Password:".strlen($hashedPw);
$query = "INSERT INTO Users SET
Name_First = ?,
Name_Last = ?,
Email = ?,
Password = ?";
// use this later?
// $result = mysqli_query($conn, $query);
if (($stmt = $db->prepare($query)) === FALSE) {
echo "Error: failed to prepare query: " . $db->error . "<br/>";
return -2;
}
if (($stmt->bind_param('ssss', $firstName, $lastName, $eMail, $hashedPw)) === FALSE) {
echo "Error: failed to bind query parameters to query: " . $db->error . "<br/>";
return -3;
}
if (($stmt->execute() && $stmt->affected_rows === 1)) {
echo "Success: new user '$userName' created<br/>";
echo "-- display login form --<br/>";
} else // failure
{
echo "Failure: new user '$userName' not created: " . $db->error . "<br/>";
echo "-- redisplay registration form --<br/>";
}
echo "<h3> Account Created! You will need to wait for Manager Approval before reieveing access. </h3>";
header("Location: logIn.html");
?>