-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplyedCandidate.php
46 lines (40 loc) · 2.1 KB
/
applyedCandidate.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
<?php
include('connection.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve form data
$CandidateName = mysqli_real_escape_string($conn, $_POST['CandidateName']);
$CandidateID = mysqli_real_escape_string($conn, $_POST['CandidateID']);
$Symbol = mysqli_real_escape_string($conn, $_POST['Symbol']);
$sgpa = mysqli_real_escape_string($conn, $_POST['sgpa']);
$attendance = mysqli_real_escape_string($conn, $_POST['attendance']);
$SectionBatch = mysqli_real_escape_string($conn, $_POST['SectionBatch']);
// Check if the candidate exists in the voters table
$checkVoterQuery = "SELECT * FROM voters WHERE VID = '$CandidateID'";
$checkVoterResult = mysqli_query($conn, $checkVoterQuery);
if (mysqli_num_rows($checkVoterResult) > 0) {
// Candidate exists in voters table, check if already applied
$checkAppliedQuery = "SELECT * FROM applyCandidate WHERE CandidateID = '$CandidateID' AND SectionBatch = '$SectionBatch'";
$checkAppliedResult = mysqli_query($conn, $checkAppliedQuery);
if (mysqli_num_rows($checkAppliedResult) > 0) {
// Candidate has already applied
echo "You have already applied. Multiple applications are not allowed.";
} else {
// Candidate does not exist in applyCandidate table, proceed with the application
$sql = "INSERT INTO applyCandidate (CandidateName, CandidateID, Symbol, sgpa, attendance, SectionBatch)
VALUES ('$CandidateName', '$CandidateID', '$Symbol', '$sgpa', '$attendance', '$SectionBatch')";
if (mysqli_query($conn, $sql)) {
// echo "Candidate applied successfully!";
header('location:applyCandidate.php?SectionBatch=' . $SectionBatch);
exit();
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
} else {
// Candidate does not exist in the voters table
echo "Candidate with ID $CandidateID does not exist. Application not allowed.";
}
// Close the database connection
mysqli_close($conn);
}
?>