From 2eb45fa5129e6f08d79ac2cd7d6b6cd98ed62b16 Mon Sep 17 00:00:00 2001 From: Mohi Uddin Pabel Date: Thu, 18 Mar 2021 17:11:29 +0600 Subject: [PATCH] Removed redundant form from answer_script and improved other functionality Removed redundant form from answer_script and improved other functionality. (WEBSITE IS FULLY FUNCTIONAL) --- answer_script.php | 354 +++++++++++++++++++-------------------- contact.php | 4 +- question_edit.php | 4 +- question_submission.php | 2 +- quiz_answer_script.php | 2 +- student_Registration.php | 4 +- student_dashboard.php | 27 ++- 7 files changed, 199 insertions(+), 198 deletions(-) diff --git a/answer_script.php b/answer_script.php index cfa8360..7f70bb1 100644 --- a/answer_script.php +++ b/answer_script.php @@ -3,120 +3,117 @@ require_once "assets/connect/pdo.php"; if (!isset($_SESSION['Student_ID']) && !isset($_SESSION['Batch']) && !isset($_SESSION['Section'])) { - header("Location: student_login.php"); - return; + header("Location: student_login.php"); + return; } -$question_id = $_GET['id']; -$title = $_GET['title']; -$course_title = $_GET['ct']; -$course_code = $_GET['cc']; -$batch = $_GET['batch']; -$section = $_GET['sec']; - // Variables declared as empty for persisting data on the form -$name = $student_id = $batch = $section = $success = $failed = $reg_done = ''; +$name = $student_id = $batch = $section = $success = $failed = $answer = ''; // errors array to put all the error message in the array -$errors = array('name' => '', 'student_id' => '', 'batch' => '', 'section' => ''); - -// Validating and setting data in variables from first form - -if (isset($_POST["submit"])) { - - //check name - if (empty($_POST['name'])) { - $errors['name'] = 'A name is required'; - } else { - $name = $_POST['name']; - if (!preg_match('/^[a-zA-Z\s]+$/', $name)) { - $errors['name'] = 'Name must be letters and spaces only'; - } - } - - //student id check - if (empty($_POST['student_id'])) { - $errors['student_id'] = 'Student ID is required.'; - } else { - $student_id = $_POST['student_id']; - if (!preg_match('/^[0-9]*$/', $student_id)) { - $errors['student_id'] = 'ID must be numbers only.'; - } else if ($_POST['student_id'] != $_SESSION['Student_ID']) { - $errors['student_id'] = 'You cannot put others student ID.'; - } - } +$errors = array('name' => '', 'student_id' => '', 'batch' => '', 'section' => '', 'answer' => ''); - //batch check - if (empty($_POST['batch'])) { - $errors['batch'] = 'Batch is required.'; - } else { - $batch = $_POST['batch']; - if (!preg_match('/^[0-9]*$/', $batch)) { - $errors['batch'] = 'Batch must be numbers only.'; - } else if ($_POST['batch'] != $_SESSION['Batch']) { - $errors['batch'] = 'You should put your batch only'; - } - } - //section check - if (empty($_POST['section'])) { - $errors['section'] = 'Section is required.'; - } else { - $section = $_POST['section']; - if (!preg_match('/^[a-zA-Z\s]+$/', $section)) { - $errors['section'] = 'Section must be a character.'; - } else if ($_POST['section'] != $_SESSION['Section']) { - $errors['section'] = 'You should put your section only (case-sensitive)'; - } - } - if (array_filter($errors)) { - //echo 'errors in form'; - } else { - //setting info in variables here - $name = $_POST['name']; - $student_id = $_POST['student_id']; - $batch = $_POST['batch']; - $section = $_POST['section']; - - $reg_done = ""; - } -} //fetching questions and other data if (isset($_GET['id'])) { - $question_id = $_GET['id']; - require_once "assets/connect/pdo.php"; - $stmt = $pdo->query("SELECT * FROM question_description WHERE Question_Description_ID = $question_id"); + $question_id = $_GET['id']; + require_once "assets/connect/pdo.php"; + $stmt = $pdo->query("SELECT * FROM question_description WHERE Question_Description_ID = $question_id"); - $infos = $stmt->fetchAll(PDO::FETCH_ASSOC); + $infos = $stmt->fetchAll(PDO::FETCH_ASSOC); } + + + //inserting answer in database if (isset($_POST["ansSubmit"])) { - $ansName = $_POST['ansName']; - $ansId = $_POST['ansId']; - $ansBatch = $_POST['ansBatch']; - $ansSec = $_POST['ansSec']; - $ansQuestion_ID = $_POST['ansQuestion_ID']; + $name = $_POST['name']; + $student_id = $_POST['student_id']; + $batch = $_POST['batch']; + $section = $_POST['section']; + $answer = $_POST['answer']; + $question_id = $_POST['question_id']; + + + + //name check + if (empty($_POST['name'])) { + $errors['name'] = 'A name is required'; + } else { + $name = $_POST['name']; + if (!preg_match('/^[a-zA-Z\s]+$/', $name)) { + $errors['name'] = 'Name must be letters and spaces only'; + } + } + + //student id check + if (empty($_POST['student_id'])) { + $errors['student_id'] = 'Student ID is required.'; + } else { + $student_id = $_POST['student_id']; + if (!preg_match('/^[0-9]*$/', $student_id)) { + $errors['student_id'] = 'ID must be numbers only.'; + } else if ($_POST['student_id'] != $_SESSION['Student_ID']) { + $errors['student_id'] = 'You should put your student ID only.'; + } + } + + //batch check + if (empty($_POST['batch'])) { + $errors['batch'] = 'Batch is required.'; + } else { + $batch = $_POST['batch']; + if (!preg_match('/^[0-9]*$/', $batch)) { + $errors['batch'] = 'Batch must be numbers only.'; + } else if ($_POST['batch'] != $_SESSION['Batch']) { + $errors['batch'] = 'You should put your batch only'; + } + } + + //section check + if (empty($_POST['section'])) { + $errors['section'] = 'Section is required.'; + } else { + $section = $_POST['section']; + if (!preg_match('/^[a-zA-Z\s]+$/', $section)) { + $errors['section'] = 'Section must be a character.'; + } else if ($_POST['section'] != $_SESSION['Section']) { + $errors['section'] = 'You should put your section only (case-sensitive)'; + } + } + + //answer field check + if (empty($_POST['answer'])) { + $errors['answer'] = 'Answer field cannot be empty.'; + } else { $answer = $_POST['answer']; + } - try { - require_once "assets/connect/pdo.php"; + if (array_filter($errors)) { + //echo 'errors in form'; + } else { - $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $sql = "INSERT INTO student_answer (Full_Name, Student_ID, Batch, Section, Question_Description_ID, Answer) VALUES('$ansName', '$ansId', '$ansBatch', '$ansSec', '$ansQuestion_ID', '$answer')"; - // use exec() because no results are returned - $pdo->exec($sql); - $success = ""; + $name = $_POST['name']; + $student_id = $_POST['student_id']; + $batch = $_POST['batch']; + $section = $_POST['section']; + $answer = $_POST['answer']; + $question_id = $_POST['question_id']; + + + try { + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $sql = "INSERT INTO student_answer (Full_Name, Student_ID, Batch, Section, Question_Description_ID, Answer) VALUES('$name', '$student_id', '$batch', '$section', '$question_id', '$answer')"; + // use exec() because no results are returned + $pdo->exec($sql); + $success = ""; } catch (PDOException $e) { - $err = $e->getMessage(); - $failed = ""; + $err = $e->getMessage(); + $failed = ""; } $ownBatch = $_SESSION['Batch']; @@ -124,6 +121,11 @@ $_SESSION['ExamDone'] = "Thank you for attending the Exam. Your answer script has been recieved."; sleep(2); header("Location: student_dashboard.php?batch=$ownBatch&sec=$ownSection"); + } + // echo '
';
+  // var_dump($infos);
+  // echo '
'; + } ?> @@ -133,16 +135,16 @@ + require_once 'assets/connect/head.php'; + require_once 'assets/summer_Note/summer_Note.php'; + ?>
@@ -163,112 +165,96 @@
-

Don't forget to attach your details first before handing over your answer script.

- +

Fill in the form first before handing over to the answer script.

- -
-
-
-
- - -
-
- - -
-
-
-
- - -
+ + -
- - + +
+
+
+ + +
+ +
+ + +
-
-
-
- +
+
+ + +
+ +
+ + +
-
- - - - -
- - -
-
-

Leading University

-
-
+ -
-
-
Department of CSE
-
-
+ +
+
+
+

Leading University

+
+
-
-
-
-
-
+
+
+
Department of CSE
+
+
-
-
-
Course Title:
-
-
+
+
+
+
+
-
-
-
Course Code:
-
-
+
+
+
Course Title:
+
+
-
-
-
Batch:
-
-
+
+
+
Course Code:
+
+
-
-
-
Section:
-
-
+
+
+
Batch:
+
+
- - -
- - - - - - - +
+
+
Section:
+
+
+

- - + - + + - -

- +
@@ -291,9 +275,9 @@
-
+ -
+
diff --git a/contact.php b/contact.php index 8c6537b..e222075 100644 --- a/contact.php +++ b/contact.php @@ -25,9 +25,9 @@ $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; // Gmail ID which you want to use as SMTP server - $mail->Username = 'luexamhive@gmail.com'; + $mail->Username = ''; // Gmail Password - $mail->Password = 'examhive44'; + $mail->Password = ''; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = 587; diff --git a/question_edit.php b/question_edit.php index 3806877..4a5e384 100644 --- a/question_edit.php +++ b/question_edit.php @@ -66,8 +66,8 @@
-
-
+
+

Edit Question

diff --git a/question_submission.php b/question_submission.php index daabb8f..fb95ca0 100644 --- a/question_submission.php +++ b/question_submission.php @@ -45,7 +45,7 @@ diff --git a/quiz_answer_script.php b/quiz_answer_script.php index d0562c2..dcc9b69 100644 --- a/quiz_answer_script.php +++ b/quiz_answer_script.php @@ -79,7 +79,7 @@ $batch = $_POST['batch']; $section = $_POST['section']; - $reg_done = "