Php 登录系统赢得';t将新用户重定向到右侧页面

Php 登录系统赢得';t将新用户重定向到右侧页面,php,Php,在游戏中工作&我添加了一个功能,在用户注册时为用户提供“主坐标”,它将一组随机坐标连同他们的所有其他信息一起插入数据库,然后登录用户 登录系统会将用户重定向到正确的页面,除非他们是新的寄存器,在这种情况下,它只会将他们定向到0,0。我不知道为什么会这样 function login($username, $password) { $password = $this->passwordEncryption($_POST['password']); $sql =

在游戏中工作&我添加了一个功能,在用户注册时为用户提供“主坐标”,它将一组随机坐标连同他们的所有其他信息一起插入数据库,然后登录用户

登录系统会将用户重定向到正确的页面,除非他们是新的寄存器,在这种情况下,它只会将他们定向到0,0。我不知道为什么会这样

    function login($username, $password)
    {
    $password = $this->passwordEncryption($_POST['password']);
    $sql = "SELECT count(uid), uid, homeX, homeY FROM users WHERE username = :username AND password = :password";
    $que = $this->db->prepare($sql);
    $que->bindParam('username', $_POST['username']);
    $que->bindParam('password', $password );
    try{ 
        $que->execute();
        while($row = $que->fetch(PDO::FETCH_BOTH))
        {
            if($row[0] == 0)
            {
                $error = 'who do you think you are?';
                echo $error;
            }
            else
            {
                $_SESSION['uid'] = $row[1];
                $x = $row[2];
                $y = $row[3];
                $index = "index.php?X={$x}&Y={$y}";
                return $index;
                //* Start the Session Timer
                $_SESSION['SS'] = time();
            }
        }
    }catch(PDOException $e) { echo $e->getMessage();}   
}

    function registerUser($password, $username)
{
    if($this->checkUsername($username) == 'chr')
    {
        header('location:index.php?error=nameC');
    }
    if($this->checkUsername($username) == 'short')
    {
        header('location:index.php?error=nameL');   
    }
    if(!$this->checkUsername($username))
    {
        header('location:index.php?error=taken');   
    }
    else
    {
    if(strlen($password) == 0)
    {
        header('location:index.php?error=pass');
    }
    else
    {
        $password = $this->passwordEncryption($password);
        $x = rand(-16, 16);
        $y = rand(-16, 16);
        $sql = "INSERT INTO users(username, password, homeX, homeY) VALUES (:username, :password, :X, :Y);";
        $sql .= "INSERT INTO bank_accounts(balance, fuel_cell, energy_cell) VALUES (10000,575, 575);";
        $sql .= "INSERT INTO user_upgrades(science, technology, economy, religion, military) VALUES(1,1,1,1,1)";
        $que = $this->db->prepare($sql);
        $que->bindParam('username', $username);
        $que->bindParam('password', $password);
        $que->bindParam('Y', $y);
        $que->bindParam('X', $x);

        try{
             $que->execute(); 
             $que->nextRowset();
             $que->nextRowset();
             $this->login($username, $password);
             }

             catch(PDOException $e){}
        }
    }
}

我相信您会问,为什么新寄存器总是重定向到0,0的cordinate。这很可能是因为该表对于该新用户没有任何值,并且对于数据库中的homeX和homeY列,该表在数据库中将是0。很难说清楚,因为我们无法知道用户注册时是否设置了这些值,因为代码只显示登录名

我还要注意,返回后的任何代码都不会执行。在确认用户已登录的
else
语句中,您将在会话之前返回

return $index;
//* Start the Session Timer
$_SESSION['SS'] = time();
会话将永远不会被设置

编辑更新。您没有正确绑定这些值

    $que->bindParam(':username', $username);
    $que->bindParam(':password', $password);
    $que->bindParam(':Y', $y);
    $que->bindParam(':X', $x);

“登录系统会将用户重定向到正确的页面,除非他们是新的注册表,”那么插入代码在哪里?我看到的只是SELECT,这意味着只有预注册的用户才能看到此代码。您在哪里提出了错误消息?我还以为我还包括了注册功能。我的错。