PHP SCRIPT TO RETRIEVE QUESTIONS RANDOMLY AND DISPLAY IT ON A HTML FORM
i am making use of a session variable to store the retrieve data, and i create a class with a function, so that any time the function is called it will retrieve data form the question table and assign the retrieve values to the session variables but i am having this error saying.
! ) Parse error: syntax error, unexpected ''startExam.php'' (T_CONSTANT_ENCAPSED_STRING) in C:\wamp\www\examSystem\student.php on line 6
**************************************************
this is my code
<?php session_start(); ?>
<?php
class startExam
{
$_SESSION['answers1'];
$_SESSION['answers2'];
$_SESSION['answers3'];
$_SESSION['answers4'];
$_SESSION['Q_ID'];
$_SESSION['question'];
function loop()
{
$con=mysqli_connect("localhost","root","","online_ exam");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_SESSION['$Q_ID']))
$_SESSION['Q_ID'] = $_SESSION['Q_ID']+ 1;
else
$_SESSION['Q_ID'] = 1;
$id = $_SESSION['Q_ID'];
$result = mysqli_query($con,"SELECT * FROM question WHERE Question_ID = '$id'");
$Quest;
while($row = mysqli_fetch_array($result))
{
$_SESSION['question'] = $row['Quest'];
}
$AnsResult = mysqli_query($con,"SELECT * FROM answers WHERE answer_id = '$id'");
while($Ans = mysqli_fetch_array($AnsResult))
{
$_SESSION['answers1'] = $Ans['answer1'];
$_SESSION['answers2'] = $Ans['answer2'];
$_SESSION['answers3'] = $Ans['answer3'];
$_SESSION['answers4'] = $Ans['answer4'];
}
mysqli_close($con);
// header('Location: http:student.php');
}
}
?>
and this code is to trigger the function and display the data
********************************
<?php session_start();
?>
<?php
required_once 'startExam.php';
$myChange = new startExam();
if(isset($_POST['submit']))
{
$myChange->loop();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Student page</title>
<link rel="stylesheet" type="text/css" href="Admin.css">
<link rel="stylesheet" type="text/css" href="Login.css">
<link rel="stylesheet" type="text/css" href="Student.css">
</head>
<body style = "background-color:#F5F5F5">
<p id ="bgr">
<table>
<tr>
<th></th>
<th></th>
</tr>
<tr>
<td>
<img src = "image/logo5.jpg"height="100"width="600" border="0"/>
</td>
</tr>
</table>
</p>
<p>
<hr id = "line1">
<img src = "image/stu.jpg"height="40"width="120" border="0"/> <br/>
<a href="login.html">Logout</a>
</p>
<!--menu-->
<nav>
<p>
<table>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<td id="menu">
</td>
</tr>
<tr>
<td id="menu">
<a href="/E/">End Exam</a>
</td>
</tr>
<br/>
<br/>
<tr>
<td id="menu">
</td>
</table>
</p>
</nav>
<center>
<br/>
<form action = "<?=$_SERVER['PHP_SELF'];?>" method = "post">
<table>
<caption><?php echo $_SESSION['question'];?></caption>
<tr><td><input type = "radio" name = "value1"/></td><td> </td>
</tr>
<tr><td><input type = "radio" name = "value1"/></td><td> <?php //echo $_SESSION['answers2'];?> </td>
</tr>
<tr><td><input type = "radio" name = "value1"/></td><td> <?php //echo $_SESSION['answers3'];?> </td>
</tr>
<tr><td><input type = "radio" name = "value1"/></td><td> <?php //echo $_SESSION['answers4'];?> </td>
</tr>
</table>
<input type="button" value = "CONTINUES">
</form>
</center>
</body>
</html>
-
Brandon Tanner -
[ 1 ] Thanks
Signature{{ DiscussionBoard.errors[8648564].message }} -
-
lloydblinks -
Thanks
{{ DiscussionBoard.errors[8651604].message }} -
-
Andrew H -
[ 1 ] Thanks
Signature"You shouldn't come here and set yourself up as the resident wizard of oz." {{ DiscussionBoard.errors[8651856].message }} -
-
lloydblinks -
Thanks
{{ DiscussionBoard.errors[8656004].message }} -