-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
62 lines (50 loc) · 2.16 KB
/
Copy pathsignup.php
File metadata and controls
62 lines (50 loc) · 2.16 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
56
57
58
59
60
61
62
<?php
session_start();
require_once('db.php');
if (isset($_POST)) {
$fname = mysqli_real_escape_string($conn, $_POST['fname']);
$lname = mysqli_real_escape_string($conn, $_POST['lname']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$status = 'Active';
$emailcheck = "SELECT * FROM student_info WHERE user_email = '$email'";
$result = $conn->query($emailcheck);
if ($result->num_rows == 0) {
$sql = "INSERT INTO student_info (firstname, lastname, user_email, user_pass, status)
VALUES ('$fname', '$lname', '$email', '$password', '$status')";
if ($conn->query($sql) == TRUE) {
$sql1 = "SELECT * FROM student_info WHERE user_email='$email' AND user_pass='$password'";
$result1 = $conn->query($sql1);
if ($result1->num_rows > 0) {
while ($row = $result1->fetch_assoc()) {
$_SESSION['logged_in'] = 'yes';
$_SESSION['fullname'] = $row['firstname'] . ' ' . $row['lastname'];
$_SESSION['status'] = $row['status'];
$_SESSION['id'] = $row['user_id'];
$_SESSION['role'] = 'User';
}
}
$user_id = $row['user_id'];
$activity = 'Registered User (' . $row['firstname'] . ' ' . $row['lastname'] . ')';
$audit = "INSERT INTO audit_trails (user_id, activity) VALUES ('$user_id', '$activity')";
$conn->query($audit);
$_SESSION['RegisterSuccess'] = true;
header("Location: users/index.php");
exit();
} else {
//If data failed to insert then show that error. Note: This condition should not come unless we as a developer make mistake or someone tries to hack their way in and mess up
echo "Error " . $sql . "<br>" . $conn->error;
}
} else {
//if email found in database then show email already exists error.
$_SESSION['RegisterFailed'] = true;
header("Location: register.php");
exit();
}
//Close database connection. Not compulsory but good practice.
$conn->close();
} else {
//redirect them back to register page if they didn't click register button
header("Location: register.php");
exit();
}