简体   繁体   English

使用php和sql会话的在线测验系统

[英]Online quiz system using php and sql session

I am currently working on a online quiz system which stores the value user answers in the database but only the marks and not the questions .On quiz page one question is selected among 10 question using random function of php .i am creating sessions for user login each time and storing variable in session variable..please help as am new to this web world .. 我目前正在开发一个在线测验系统,它将值用户答案存储在数据库中,但仅存储标记而不是问题。在测验页面中,使用php的随机函数在10个问题中选择了一个问题。我正在为用户登录创建会话每次在会话变量中存储变量。请帮助我作为这个网络世界的新手..

I face the following problems as :- 我面临以下问题: -

1-Now whenever i try to store the the answer in database it is incremented once and if refresh the page it again increments once and this ay the times i refresh ..which is disgracefull is there any way to avoid this and increase marks coloumn of user only once. 1 - 现在,每当我尝试将答案存储在数据库中时,它会递增一次,如果刷新页面,它会再次递增一次,这是我刷新的时间..这是可耻的有任何方法可以避免这种情况并增加标记颜色用户只有一次。

2.The second thing is that how i can select next question in quiz page ie selecting one 1/10 question each time without refreshing page and simultaneously hiding other questions like we do in quiz system using php without using random function 2.第二件事是如何在测验页面中选择下一个问题,即每次选择一个1/10问题而不刷新页面,同时隐藏其他问题,就像我们在测验系统中使用PHP而不使用随机函数一样

My code is--using 4 questions on page- 我的代码是 - 在页面上使用4个问题 -

<?php
session_start();
$username=$_SESSION['username'];
$total=$_SESSION['total'];
$q1=isset($_POST['q1']);
$q2=isset($_POST['q2']);
$q3=isset($_POST['q3']);
$q4=isset($_POST['q4']);
$q5=isset($_POST['q5']);
$full=30;
echo 'Welcome '.$username;
echo $total;

function quiz(){
$set=rand(1,5);
$total=0;

echo $set;
 switch($set)
 {

 case 1:

 echo '<form action="quiz.php" method="post" align="center">
<table align="center">
<tr><label name="question" id="ques"><h1 >ISM stands for?</h1></label><tr>
<tr>
<td align="right"><input type="radio" name="q1" value="A"></td>
<td>Indian School Of Mines</input><br></td>
</tr>

<tr>
<td align="right"><input type="radio" name="q1" value="B"></td>
<td >Indian Science Of Mines</input><br></td>
</tr>

<tr>
<td align="right"><input type="radio" name="q1" value="C"></td>
<td>Indian School Of Mineral</input><br></td>
</tr>

<tr >
<td align="right"><input type="radio" name="q1" value="D"></td>
<td>Indian School Of Machines</input><br></td>
</tr>

<tr >


<td align="center"><br><input type="submit" name="snext" value="Save/Next"><br></td>
</tr>

</form>';



if(isset($_POST['q1'])=='A')
{
$total =$total + 1;
include ('process.php');

}
else{

}

break;

case 2:

 echo '<form action="quiz.php" method="post" align="center" id="">
<table align="center">
<tr><label name="question" id="ques"><h1 >HTML stands for?</h1></label><tr>
<tr>
<td align="right"><input type="radio" name="q2" value="A"></td>
<td>Indian School Of Mines</input><br></td>
</tr>

<tr>
<td align="right"><input type="radio" name="q2" value="B"></td>
<td >Indian Science Of Mines</input><br></td>
</tr>

<tr>
<td align="right"><input type="radio" name="q2" value="C"></td>
<td>Indian School Of Mineral</input><br></td>
</tr>

<tr >
<td align="right"><input type="radio" name="q2" value="D"></td>
<td>Indian School Of Machines</input><br></td>
</tr>

<tr >



<td align="center"><br><input type="submit" name="snext" value="Save/Next"><br></td>
</tr>

</form>';


if(isset($_POST['q2'])=='C')
{
$total =$total + 1;
include ('process.php');

}
else{

}
break;


case 3:

 echo '<form action="quiz.php" method="post" align="center">
<table align="center">
<tr><label name="question" id="ques"><h1 >CSS stands for?</h1></label><tr>
<tr>
<td align="right"><input type="radio" name="q3" value="A"></td>
<td>Indian School Of Mines</input><br></td>
</tr>

<tr>
<td align="right"><input type="radio" name="q3" value="B"></td>
<td >Indian Science Of Mines</input><br></td>
</tr>

<tr>
<td align="right"><input type="radio" name="q3" value="C"></td>
<td>Indian School Of Mineral</input><br></td>
</tr>

<tr >
<td align="right"><input type="radio" name="q3" value="D"></td>
<td>Indian School Of Machines</input><br></td>
</tr>

<tr >


<td align="center"><br><input type="submit" name="snext" value="Save/Next"><br></td>
</tr>

</form>';
if(isset($_POST['q3'])=='D')
{
$total =$total + 1;
include ('process.php');

}
else{

}
break;


case 4:

 echo '<form action="quiz.php" method="post" align="center">
<table align="center">
<tr><label name="question" id="ques"><h1 >PHP stands for?</h1></label><tr>
<tr>
<td align="right"><input type="radio" name="q4" value="A"></td>
<td>Indian School Of Mines</input><br></td>
</tr>

<tr>
<td align="right"><input type="radio" name="q4" value="B"></td>
<td >Indian Science Of Mines</input><br></td>
</tr>

<tr>
<td align="right"><input type="radio" name="q4" value="C"></td>
<td>Indian School Of Mineral</input><br></td>
</tr>

<tr >
<td align="right"><input type="radio" name="q4" value="D"></td>
<td>Indian School Of Machines</input><br></td>
</tr>

<tr >


<td align="center"><br><input type="submit" name="snext" value="Save/Next"><br></td>
</tr>
</table>
</form>';
if(isset($_POST['q4'])=='D')
{
$total =$total + 1;
include ('process.php');

}
else{

}
break;



default:

Echo "This is quiz application";

break;

}

}

?>

<html>
<head>
</head>

<body>
<?php echo quiz(); ?>

</body>
</html>

Just as a small hint to start: 就像一个小小的提示开始:

use 采用

if(isset($_POST['q1']) && $_POST['q1']=='A'){
  ...
}

isset($_POST['q1']) just checks if $_POST['q1'] is set or not. isset($_POST['q1'])只检查是否设置了$_POST['q1']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM