问卷中的最后一页,用提交按钮替换下一个按钮?

时间:2015-12-31 00:54:20

标签: php jquery html forms form-submit

我想这样做,以便我的测验的最后一页在结尾处有一个提交按钮。现在,如果测验是空的,完成的或没有问题,会出现前进和后退按钮。

当来自数据库的一组四个答案没有显示时(由于是空字符串),那么我该如何制作它以便出现一个Submit按钮并替换下一个按钮?

我的SQL表由qid(int),answer(varchar),point(int)

组成

代码(PHP / HTML)

<html>
    <head>
        <meta charset="utf-8">
        <script>
function goBack() {
    window.history.go(-1);
}
</script>
    </head>
    <body>
<?php
$localhost = "localhost";
$username = "root";
$password = "";
$connect = mysqli_connect($localhost, $username, $password) or die ("Kunde inte koppla");
mysqli_select_db($connect, 'wildfire');

$qid = 1; 
if(count($_POST) > 0){ 
$qid = intval($_POST['qid'])+1; 
}
?>  
        <form method="post" action="">
            <input type="hidden" name="qid" value="<?=$qid?>">
            <?php
                $sql1 = mysqli_query($connect,"SELECT * FROM question where answer != '' && qid =".intval($qid));
                while($row1=mysqli_fetch_assoc($sql1)){
                ?>
                <input type='radio' name='answer1' value="<?php echo $row1['Point'];?>"><?php echo $row1['answer'];?><br>
                <?php
                }
            ?>
                <button type="button" onclick="history.back();">Tillbaka</button>
            <input type='submit' name='forward' value='Nästa'>

        </form>
    </body>

</html>

0 个答案:

没有答案