-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_self_assess.php
More file actions
86 lines (73 loc) · 2.39 KB
/
save_self_assess.php
File metadata and controls
86 lines (73 loc) · 2.39 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
session_start();
require 'db.php';
/* ===== GET FORM DATA ===== */
$full_name = trim($_POST['full_name']);
$email = trim($_POST['email']);
$password = $_POST['password'];
$hiring_id = $_POST['hiring_id'] ?? null;
/* ===== BASIC VALIDATION ===== */
if (empty($full_name) || empty($email) || empty($password)) {
die("Required fields missing.");
}
/* ===== CHECK IF EMAIL ALREADY REGISTERED ===== */
$checkUser = $conn->prepare("SELECT id FROM applicants_users WHERE email=?");
$checkUser->bind_param("s", $email);
$checkUser->execute();
$userResult = $checkUser->get_result();
/* ===== IF NOT EXIST → CREATE ACCOUNT ===== */
if ($userResult->num_rows == 0) {
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$insertUser = $conn->prepare("
INSERT INTO applicants_users (full_name, email, password, status)
VALUES (?,?,?,'Pending')
");
$insertUser->bind_param("sss", $full_name, $email, $hashedPassword);
$insertUser->execute();
}
/* ===== PROCESS CHECKBOX VALUES ===== */
$education = isset($_POST['education']) ? 1 : 0;
$training = isset($_POST['training']) ? 1 : 0;
$experience = isset($_POST['experience']) ? 1 : 0;
$eligibility = isset($_POST['eligibility']) ? 1 : 0;
/* ===== SAVE SELF ASSESSMENT (Prevent Duplicate) ===== */
$checkAssess = $conn->prepare("SELECT id FROM self_assess WHERE email=?");
$checkAssess->bind_param("s", $email);
$checkAssess->execute();
$assessResult = $checkAssess->get_result();
if ($assessResult->num_rows == 0) {
$stmt = $conn->prepare("
INSERT INTO self_assess
(full_name,email,education,training,experience,eligibility)
VALUES (?,?,?,?,?,?)
");
$stmt->bind_param("ssiiii",
$full_name,
$email,
$education,
$training,
$experience,
$eligibility
);
$stmt->execute();
}
/* ===== SHOW ALERT INSTEAD OF REDIRECT ===== */
$redirect = $hiring_id
? "registration.php?hiring_id=".$hiring_id
: "applicant_dashboard.php?assessed=1";
echo "
<!DOCTYPE html>
<html>
<head>
<title>Registration Submitted</title>
</head>
<body>
<script>
alert('Your account has been successfully created!\\n\\nPlease wait for Admin approval. You will receive an email once your account is activated.');
window.location.href = '$redirect';
</script>
</body>
</html>
";
exit;
?>