| Current Path : /var/www/html/venkat/aviral/aviral/ |
| Current File : //var/www/html/venkat/aviral/aviral/reg_submit.php |
<?php
include('db1.php');
include('session.php');
?>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<center>
<?php
$id = addslashes($_SESSION['key']);
$_backButton = '<div class="container"><form action="register.php"><button type="submit">Go Back</button></form></div>';
if (!isset($_POST['sel'])) {
echo '<h4>No choices selected.</h4>';
echo $_backButton;
exit;
}
$courses = $_POST['sel'];
$totalcredits = 0;
// print_r($courses);
foreach ($courses as $courseid) {
$id = addslashes($_SESSION['key']);
$q = $conn->prepare("select course_id from aviral_registered where student_id = :id");
$q->bindValue(":id", $id);
$q->execute();
$flag = 0;
while ($row = $q->fetch(PDO::FETCH_ASSOC)) {
$course_id = $row['course_id'];
//if (in_array($course_id, $courses)) {A
if ($course_id == $courseid) {
$flag = 1;
}
$qi = $conn->prepare("select * from aviral_courses where id = :courseid");
$qi->bindValue(":courseid", $courseid);
$qi->execute();
$course = $qi->fetch(PDO::FETCH_ASSOC);
if (!$course) {
echo 'ERR: Course id ' . $courseid . ' not found. Please report this to the developer.';
die();
} else {
$course_code = $course['course_code'];
$course_name = $course['course_name'];
$semester = $course['semester'];
$L = $course['L'];
$T = $course['T'];
$P = $course['P'];
$total_credits += ($L + $T + $P);
}
}
$qi = $conn->prepare("select * from aviral_courses where id = :courseid");
$qi->bindValue(":courseid", $courseid);
$qi->execute();
$course = $qi->fetch(PDO::FETCH_ASSOC);
if (!$course) {
echo 'ERR: Course id ' . $courseid . ' not found. Please report this to the developer.';
die();
} else {
$course_code = $course['course_code'];
$course_name = $course['course_name'];
$semester = $course['semester'];
$L = $course['L'];
$T = $course['T'];
$P = $course['P'];
if (($L + $T + $P + $totalcredits) < 12) {
if ($flag === 1) {
echo 'Already registered course: ' . $course_name . '<br>';
$flag = 0;
continue;
}
$qi = $conn->prepare("insert into aviral_registered (student_id, course_id) values (:id, :courseid)");
$qi->bindValue(":id", $id);
$qi->bindValue(":courseid", $courseid);
$qi->execute();
if ($qi->rowCount() == -1) {
echo 'ERR: Unable to add course: ' . $courseid . '!<br>';
} else {
echo 'Registered course: ' . $course_name . '<br>';
}
$totalcredits += ($L + $T + $P);
} else {
echo 'Unable to add course: ' . $course_name . ' due to excess credits. Consider removing a course to add this course.';
}
}
}
echo $_backButton;
?>