Greetings all, I am working on a computer based test application, where when the student logs in to test the test, the questions should come from the subjects the student was registered for.
Display results from DB using variables.
4
Greetings all,
I am working on a computer based test application, where when the student logs in to test the test, the questions should come from the subjects the student was registered for.
I have tried using SESSION variable to hold the registered subjects and pass them to the query that will fetch the questions,but won't work.
here is a snippet my php code so far,
<?php
<?php
//confirm session
if(isset($_SESSION['user'])){ echo $_SESSION['user'];}
else{die("Session not started");}
//get student's details using session variables
$confirmuser=mysql_query("select * from students where username='$user' ") or die(mysql_error());
while($confirm=mysql_fetch_array($confirmuser)){ec ho"<br/>";
echo $confirm['surname'].'<br/>';
echo $confirm['firstname'].'<br/>';;
echo $_SESSION['subject1'] =$confirm['subject1'].'<br/>';
echo $_SESSION['subject2']=$confirm['subject2'].'<br/>';
echo $_SESSION['subject3']=$confirm['subject3'].'<br/>';
echo $_SESSION['subject4'] =$confirm['subject4'].'<br/>';
echo '<br/>';
$fourthsubject=$_SESSION['subject2'];
echo $fourthsubject. '<br/>';
function fourth(){ global $fourthsubject;
$bend=mysql_query("select * from $subject3 ") or die(mysql_error());
while($rase=mysql_fetch_array($bend)){
echo $rase['question'];}
;}
fourth();
}
?>
The above code is displaying this error message (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
' at line 1)
I am working on a computer based test application, where when the student logs in to test the test, the questions should come from the subjects the student was registered for.
I have tried using SESSION variable to hold the registered subjects and pass them to the query that will fetch the questions,but won't work.
here is a snippet my php code so far,
<?php
<?php
//confirm session
if(isset($_SESSION['user'])){ echo $_SESSION['user'];}
else{die("Session not started");}
//get student's details using session variables
$confirmuser=mysql_query("select * from students where username='$user' ") or die(mysql_error());
while($confirm=mysql_fetch_array($confirmuser)){ec ho"<br/>";
echo $confirm['surname'].'<br/>';
echo $confirm['firstname'].'<br/>';;
echo $_SESSION['subject1'] =$confirm['subject1'].'<br/>';
echo $_SESSION['subject2']=$confirm['subject2'].'<br/>';
echo $_SESSION['subject3']=$confirm['subject3'].'<br/>';
echo $_SESSION['subject4'] =$confirm['subject4'].'<br/>';
echo '<br/>';
$fourthsubject=$_SESSION['subject2'];
echo $fourthsubject. '<br/>';
function fourth(){ global $fourthsubject;
$bend=mysql_query("select * from $subject3 ") or die(mysql_error());
while($rase=mysql_fetch_array($bend)){
echo $rase['question'];}
;}
fourth();
}
?>
The above code is displaying this error message (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
' at line 1)
- KirkMcD
- KirkMcD
- Fanzi
Next Topics on Trending Feed
-
4