为什么我的代码在此之后无法执行

时间:2020-09-04 04:02:27

标签: php html mysql

我在玩php,但是脚本没有执行到最后一点,没有错误...

我想做的是检查用户的输入并比较它在db中的内容,然后应用条件。所以我有2个文件。 update.php dash.php

dash.php 是我的html表单页面,我在其中添加了“ update.php”

在我的 update.php 中,我有以下代码

me.php是我的html表单页面,我在其中添加了“ update.php”

在我的update.php中,我有以下代码

<?php

error_reporting(E_ALL);
include_once('database.php');

if(isset($_POST['submit']))
{
    $q = $_GET['q'];

    $next = $q + 1;

    if($q == 26)
    {
        echo '<h2>Weldone!!</h2>';
    }
    elseif($q <= 25){
        $sql = "SELECT * FROM Students WHERE Email=?";
        $stmt = $conn->prepare($sql); 
        $stmt->bind_param('s', 
                          $_SESSION['login']);
        $stmt->execute();
        $result = $stmt->get_result(); $row = $result->fetch_assoc();

        $Mark = $row['Mark'];
        $Correct = $Mark + 1;
        $Fail = $Mark + 0;

        $sqlb = "SELECT * FROM Answers WHERE qid = ?";
        $stmtb = $conn->prepare($sqlb); 
        $stmtb->bind_param('s', $q);
        $stmtb->execute();
        $resultb = $stmtb->get_result();

        $rowb = $resultb->fetch_assoc();

        $Answer = 
            $rowb['Answer'];

        $Pick = $_POST['ans'];

        if($Pick ==  $Answer)
        {
            $sqld = "UPDATE Students SET Mark=? WHERE Email = ?";
            $stmtd = $conn->prepare($sqld); 
            $stmtd->bind_param('ss', $Correct,$_SESSION['login']);
            $stmtd->execute();
            $resultd = $stmtd->get_result();  
            echo "correct" ;
        }
    }
    else
    {
        echo "<script type='text/javascript'>document.location.href='dash.php?q='.$next.';</script>";
    }
}//post submit
?>

else语句不运行。因此它会不断重新加载同一页面。

我还想问为什么我将存储在数据库中的$ Correct变量的值保持为2而不是1而不是1,这是一个正确的问题?

最后,如果用户通过更改浏览器的$ q值来编辑浏览器,我不希望脚本运行,因为我使用的是get方法,有没有办法做到这一点。

请对您的评论满意。预先感谢。!!

0 个答案:

没有答案