0

我目前正在开发一个在线测验系统,该系统将值用户答案存储在数据库中,但只有分数而不是问题。在测验页面上,使用 php 的随机函数从 10 个问题中选择一个问题。我正在为用户登录创建会话每次并在会话变量中存储变量..请帮助这个网络世界的新手..

我面临以下问题:-

1-现在,每当我尝试将答案存储在数据库中时,它都会增加一次,如果刷新页面,它会再次增加一次,这就是我刷新的时间..这是可耻的,有什么办法可以避免这种情况并增加标记列用户只有一次。

2.第二件事是我如何在测验页面中选择下一个问题,即每次选择一个 1/10 问题而不刷新页面并同时隐藏其他问题,就像我们在使用 php 的测验系统中所做的那样,而不使用随机函数

我的代码是——在页面上使用 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>
4

1 回答 1

2

就像开始的一个小提示:

利用

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

isset($_POST['q1'])只是检查是否$_POST['q1']设置。

于 2013-03-01T15:53:51.417 回答