-
Notifications
You must be signed in to change notification settings - Fork 0
/
exam.php
38 lines (31 loc) · 1.2 KB
/
exam.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
<?php
session_start();
if(!isset($_SESSION['user_id']))
{
die('You are not logged in. Please <a href="./">log in</a>.');
}
$title='Questions - Online examination system';
require('./template/header.php');
require_once('./includes/db_connect.php');
$db = db_connect();
$qr = $db->prepare("SELECT q_body, q_ans1, q_ans2, q_ans3, q_ans4 FROM questions WHERE q_id = ?");
$qs = array();
echo '<div class="questionsBody"><form name="questions" method="post" action="result.php">';
for ($i=1; $i<=5; $i++)
{
while(in_array($qno = rand(1, 10), $qs)); //Find a number not in the array
$qs[] = $qno; //Push the number into the array
echo '<input type="hidden" name="q' . $i . '" value="' . $qno . '" />';
$qr->execute(array($qno));
$result = $qr->fetch(PDO::FETCH_ASSOC);
echo '<div class="question"><span class="corr_ques_no">Q'.$i.')</span>' . $result['q_body'] . '</div>';
echo '<div class="answer">';
for ($j=1; $j<=4; $j++)
{
echo '<input type="radio" class="answer" name="a' . $i . '" value="'. $j . '" />' . $result["q_ans$j"];
}
echo '</div>';
}
echo '</div><center></span><input type="submit" name="qSubmit" value="Submit" /></center>';
require('./template/footer.php');
?>