如何从列中获取数据并将其设置为变量以便对其进行一些操作

时间:2019-07-02 15:04:14

标签: php sql

我正在尝试创建一个测验网站,其中有一个名为Level的列。我想比较这些级别,并相应地将其发送给他们所提出的问题。这应该是cookie来存储用户进度的功能。

我尝试做fetch_column_assoc,正确选择数据。

if (isset($_POST['login_user'])) {
    $username = mysqli_real_escape_string($db, $_POST['username']);
    $password = mysqli_real_escape_string($db, $_POST['password']);

    if (empty($username)) {
        array_push($errors, "Username is required");
    }
    if (empty($password)) {
        array_push($errors, "Password is required");
    }

    if (count($errors) == 0) {
        $password = md5($password);
        $query = "SELECT * 
                    FROM users 
                    WHERE username='$username' AND password='$password'";
        $results = mysqli_query($db, $query);
        if (mysqli_num_rows($results) == 1) {
            $_SESSION['username'] = $username;
            $_SESSION['success'] = "You are now logged in";

            $sql="SELECT Level FROM users";
            $result=mysqli_query($sql);
            $row=mysqli_fetch_assoc($result);

            $sth = "SELECT Level FROM users";
            $sth->execute();
            $result = $sth->fetchColumn();

            if ($result == 1) {
                header("location : https://google.co.in");
            } elseif ($result == 2) {
                header("location : https://www.w3schools.com/");
            } else{

            }
        }else {
            array_push($errors, "Wrong username/password combination");
        }
    }
}
?>

我想访问与用户有关的级别并将其发送到他所在的级别。 请帮忙。 谢谢

0 个答案:

没有答案