I am working on result management system for secondary school.
I don't want to enter the same subject for a particular user using his/her registration number as unique id. i.e. if I enter maths for John, i must not enter maths again for John.
Below is my code:
<?php
$msg = "";
$connection = mysqli_connect("localhost", "root", "", "result_mg_db");
if (isset($_POST['submit'])) {
$regno = addslashes(strip_tags($_POST['regno']));
$subj = addslashes(strip_tags($_POST['subject']));
$examscore = addslashes(strip_tags($_POST['examscore']));
$cascore = addslashes(strip_tags($_POST['cascore']));
$date = date("Y-m-d h:i:sa");
$confirm_subj = mysqli_query($connection, "SELECT subject FROM jss1_resulttbl WHERE regno = '$regno'");
if ($confirm_subj == $_POST['subject']) {
$msg = "This subject has been registered";
} else {
if ($cascore == ""|| $examscore == ""|| $subj == "" || $regno == "" ) {
$msg = "Please fill all fields";
} else {
$reg_subj = mysqli_query($connection, "INSERT INTO jss1_resulttbl VALUES ('', '$regno', '$subj', '$examscore', '$cascore', '$date')");
if (!$reg_subj) {
echo "Subject Registration failed ";
}else {
$msg = "You have Successfully entered score for " . $subj . "<br/>";
}
}
}
}
?>