使用多个查询启动登录会话

时间:2013-11-24 09:37:31

标签: php mysql

$username = $_POST['username'];
$password = $_POST['password'];

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$query .= "SELECT balance FROM users WHERE id ='1'";

if (mysqli_multi_query($connect, $query)) {
    do {
        /* store first result set */
        if ($result = mysqli_store_result($connect)) {
            while ($row = mysqli_fetch_row($result)) {

                if($row['username'] == $username && $row['password'] == $password && $password != '' && $username != ''){
                        session_start();    
                        $_SESSION['username'] = $row['username'];
                        $_SESSION['email'] = $row['email'];
                        $_SESSION['balance'] = $row['balance'];
                        echo "Logged in successfully!";
                    } else {
                        echo "Invalid username or password!";
                    }
            }
            mysqli_free_result($result);
        }
    } while (mysqli_next_result($connect));
}

当他们发布你得到的用户名/密码时,我不确定如何将人员信息保存在会话变量中(我认为这是正确的做事方式),其他信息在他们的行上。

截至目前,我甚至无法输入检查用户名和密码的if语句

1 个答案:

答案 0 :(得分:1)

会议是前进的方向。

这是一个帮助您入门的基本教程。

$_SESSION

在您直接在服务器上运行查询之前,请先查看清理查询。

这是另一个例子:LINK