设置页面的特定持续时间

时间:2019-03-01 11:05:30

标签: php

我想指定显示表单的持续时间。假设有一个值为x=(10)的变量,每当我调用此页面时,计时器应基于当前时间,并且该表单应显示10分钟,然后此表单应自动发送。 / p>

<?php 
 include 'db_conn.php';
 if (isset($_GET['id'])) {
  $var=$_GET['id'];
$query="SELECT * FROM addquiz WHERE quz_id='$var' ";
$db=mysqli_query($conn,$query);
$res=mysqli_fetch_array($db);
$noquestions=$res['noquestion'];
$quiz=$res['title'];
}?>

<div class="container">
<form  method="POST" class="form-horizontal" >

<div style="margin-left: 30%;"><b>Your Quiz: &nbsp; &nbsp; <?php echo $quiz;?></b> &nbsp; &nbsp;  &nbsp; 
<input type="text" name="user_name" placeholder="Enter Your Name" style="height: 30px; width: 30%;"></div>
<div class="row">
<div class="col-md-12">
<div class="panel" style="margin:5%">

<?php 
$count=1;
$que="SELECT * FROM addques WHERE quz_id='$var'";
$dbd=mysqli_query($conn,$que);
    while ($cmd=mysqli_fetch_array($dbd)) {

            $quest=$cmd['qusname'];
            $ans_id=$cmd['ans_id'];
            $opt1=$cmd['qpta'];
            $opt2=$cmd['optb'];
            $opt3=$cmd['optc'];
            $opt4=$cmd['optd'];
            $answ=$cmd['answer'];?>
<b>Question &nbsp; <?php echo $count++;?>&nbsp;:<br><?php echo $quest;?></b><br><br>
<fieldset>
<input type="hidden" name="ansid[]" value="<?php echo $ans_id; ?>">
<input type="checkbox" name="ans[]" value="1"><?php echo $opt1;?><br><br>
<input type="checkbox" name="ans[]" value="2"><?php echo $opt2;?><br><br>
<input type="checkbox" name="ans[]" value="3"><?php echo $opt3;?><br><br>
<input type="checkbox" name="ans[]" value="4"><?php echo $opt4?><br><br><br>
</fieldset>
<?php } ?>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
<div class="button" style="margin-left: 60%;"> <a href="result.php?name=<?php echo $_POST['user_name'];?>"  class="btn btn-info">View Result </a></div>
</div>
</div>
</div> 
<?php
$i=0;
if (isset($_POST['submit'])) {
    $name=$_POST['user_name'];
while ( $i<$noquestions  ) { 
$query="INSERT INTO `result`(  `quz_id`, `ans_id`, `answer`,`user_name`) VALUES('";
$query.=$var .  "', '"; 
$query.=$_POST['ansid'][$i] .  "', '"; 
$query.=$_POST['ans'][$i] .   "', '";
$query.=$name .   "' )";


$db=mysqli_query($conn,$query);
$i++;
}
}
?>

1 个答案:

答案 0 :(得分:0)

这取决于您要实现的目标。

正如您所说的“每次访问页面”一样,可以使用javascript这样完成:

window.onload = function () {
    window.setTimeout(function () {
        document.form.submit();
    }, 5000);
};

您还可以通过php变量设置超时时间,如上面的注释所述,您可以使用php验证服务器端花费的时间,以确保没有人在作弊。