-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestUserRegistration.php
More file actions
55 lines (47 loc) · 1.64 KB
/
Copy pathtestUserRegistration.php
File metadata and controls
55 lines (47 loc) · 1.64 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
49
50
51
52
53
54
55
<?php
// Registration Logic Here
ini_set("display_errors", 1);
require('testSessions.php');
require('config.php');
$regLogin = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$regPatientPassword = $_POST['patientPassword'];
$regPasswordConfirm = $_POST['passwordConfirm'];
if (!$regLogin) {
$_SESSION['regError'] = 1;
$referer = "testRegister.php";
header("Location: ". $referer);
exit;
}
//check if password correct
if ($regPatientPassword != $regPasswordConfirm || $regPatientPassword == "") { //regPassword == regPatientPassword
$_SESSION['regError'] = 2;
$referer = "testRegister.php";
header("Location: ../".$referer);
exit;
} else {
// Password is valid
// Code to Check if the user has already registered
$stmt = $conn->prepare("SELECT * FROM patient WHERE email = ?"); //userLogin== email
$stmt->bind_param("s", $regLogin);
$stmt->execute();
$stmt->store_result();
$numUsers = $stmt->num_rows;
if ($numUsers == 1) {
$_SESSION['regError'] = 3;
$referer = "testRegister.php";
} else {
// Insert the New User into the Database
$stmt = $conn->prepare("INSERT INTO patient(email, patientPassword) VALUES (?, ?)"); // users== patient //userPassword == patientPassword
$hashedPw = password_hash($regPatientPassword, PASSWORD_BCRYPT);
$stmt->bind_param("ss", $regLogin, $hashedPw);
$stmt->execute();
if (isset($_SESSION['regError'])) {
unset($_SESSION['regError']);
}
$referer = "testLogin.php";
}
}
$stmt->close();
$conn->close();
header("Location: ".$referer); // send user to diff page
exit;