如何重置PHP中的每个变量?

时间:2018-09-19 15:42:15

标签: php html

我目前正在使用PHP,HTML和mySQL创建测验,以进行简单练习。但是,我一直遇到一个问题,其中显示的问题与链接到答案的实际问题不同。因此,在用户正确的地方,答案是错误的。

问题页面的内容如下:

<?php 
    session_start();

    session_unset();

    $link = mysqli_connect("xxxx","xxxx","xxxx", "xxxx");

    if(mysqli_connect_error()) {
        echo "There was an error connecting to the database!";
    }else{

        $qNo = rand(1,2);
        $query = "SELECT * FROM questions WHERE questionID = '".$qNo."'";
        $result = mysqli_query($link, $query);
        $row = mysqli_fetch_array($result);
        $answer = $row[2];
        $question = $row[1]; 

        if(isset($_POST['submit'])){
            $_SESSION['question'] = $row[1];
            $_SESSION['answer'] = $answer;
            $_SESSION['userAnswer'] = $_POST['userAnswer'];
            header("Location: process.php");
        }

        }

?>

<html>

<head>
    <title>Quiz v2</title>

</head>

<body>
    <h1>Welcome to Quiz!</h1>
    <div>
        <p><a><?php print_r($question);?></a></p>
        <form method="post">
            <label for="answer">Answer: </label><input name="userAnswer">
            <button name="submit">Answer</button>
        </form>
    </div>
</body>

</html>

这是我在流程页面上所拥有的:

<?php 
    session_start();

    $link = mysqli_connect("xxx","xxxx","xxxx", "xxxx");

    if(mysqli_connect_error()) {
        echo "There was an error connecting to the database!";
    }else{

            echo $_SESSION['userAnswer'];
            echo $_SESSION['answer'];
            echo $_SESSION['question'];

            if($_SESSION['userAnswer']==$_SESSION['answer']){

            }

        }

?>

在这里,您可以看到显示的问题是: enter image description here

但这实际上是被要求和比较的:

enter image description here

0 个答案:

没有答案