完成1级以继续在PHP中的2级

时间:2015-12-29 12:33:06

标签: php mysql pdo

我有一个用户必须完成任务的网站,在任务结束时,它将值"complete"存储在数据库的字段"level1"中。我有level1 level2 level3 level4,一旦level1完成了level1 "complete"中的查询输入,这一切都正常。 但是当我进入level2页面时,如果用户没有完成1级,它会将它们重定向到1级,这很好,但是如果他们已经完成了1级,它仍然会将它们重定向到1级。任何帮助都会受到赞赏吗?

以下是level2页面的代码:

if(empty($_SESSION['user'])) 

{
   header("Refresh:5; url=home.php");
   die("PLEASE LOG IN TO ACCESS SERVICES.....Redirecting to home page. Please wait...");
}

if($_SESSION['user']['level1'] != 'complete') {
     header("Refresh:5; url=numbers.php");
    die("PLEASE Complete STAGE 1 to continue to this stage.....Redirecting to Stage 1. Please wait...");    
}

基本上,如果级别1完成,则当前页面应该加载,但是将用户重定向回级别1.即使用户已完成级别1。

这是完成任务时level1的代码:

   <?php

require("config.php");



 if($_SESSION['user']['blacklisted_users'] == 'blocked')

 { 

    header("location: blocked.php");
 }

if($_SESSION['user']['type'] == 'admin') 

{ 

    header("location: memberlist.php");

}

   if(empty($_SESSION['user'])) 

{

    echo "<script>
    alert('Please Login to access services');
     window.location.href='home.php';
     </script>";

}

 if(!empty($_POST))
{


    if(isset($_POST['level1']))

    {


   $query = "
            SELECT
                1
            FROM users
            WHERE
                level1 = :level1 
        ";


        $query_params = array(
            ':level1' => $_POST['level1']
        );

        try
        {

            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
    $stmt->bindValue(':level1 ', $level1, PDO::PARAM_STR); 
        }
        catch(PDOException $ex)
        {

            die("Failed to run query: " . $ex->getMessage());
        }




    $query_params = array(
        ':level1' => $_POST['level1'],
        ':user_id' => $_SESSION['user']['id'],
    );



    $query = "
        UPDATE users
        SET
           level1 = :level1, level1 = 'complete'
    ";

    $query .= "
        WHERE
            id = :user_id
    ";

    try
    {
        // Execute query
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    $stmt->bindValue(":level1" , "$userid", PDO::PARAM_STR); 
    }
    catch(PDOException $ex)
    {

        die("Failed to run query: " . $ex->getMessage());
    }



    header("Location: words.php");
    die("Redirecting to private.php");
}
}

 ?>

0 个答案:

没有答案