I want to display question papers according to student's branch. I create 5 tables in database "aptitude". tables are as following: itque, etrxque, extcque, civilque, mechque.
branch name is store in 'register' database.
If student is in IT department then only IT's question paper should display.
but there is some problem in logic. question paper is not displayed according to the student's branch.
code of test.php:
<html>
<body>
<?php
require_once('appvars.php');
require_once('connectvars.php');
// Make sure the user is logged in before going any further.
if (!isset($_SESSION['user_id'])) {
echo '<span style="color:#FFF;text-align:center;"><p class="login">Please <a href="login.php"style="color: #FFFFFF">log in</a> to access this page.</p></span>';
exit();
}
else {
include("menu.php");
}
?>
<?php
$dbc=mysqli_connect("localhost","root","","register");
$query = "SELECT branch FROM user WHERE m_id = '" . $_SESSION['user_id'] . "'";
$data = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($data);
if ($row != NULL) {
$Branch = $row['branch'];
}
else {
echo '<p class="error">There was a problem .</p>';
}
?>
<form action="./result.php" method="post">
<?php
$connect = mysql_connect("localhost" ,"root","");
mysql_select_db("aptitude");
$query = mysql_query("SELECT * FROM `$Branch` ORDER BY RAND() LIMIT 10 ");
while($rows = mysql_fetch_array($query)):
$q = $rows['Q_no'];
$qus = $rows['Question'];
$a = $rows['answer1'];
$b = $rows['answer2'];
$c = $rows['answer3'];
$d = $rows['answer4'];
$ans = $rows['correct'];
echo" <p> </p>";
echo "<p>Q:- $qus <br></p>";
echo "<p> A <input type=radio name = 'answer[$q]' value = '$a'></input>$a    <br>
";
echo " B <input type=radio name = 'answer[$q]' value = '$b'></input>$b    <br>
";
echo " C <input type=radio name = 'answer[$q]' value = '$c'></input>$c    <br>
";
echo " D <input type=radio name = 'answer[$q]' value = '$d'></input>$d <br><br> </p>";
endwhile;
?>
<center><input name="cmdSubmit" type="submit" id="cmdSubmit" value="Submit"/>
</center>
</form>
</body>
</html>