0
當我的SQL查詢中選擇的行數大於0且其他設置爲false時,我的登錄會話設置爲true時遇到了一些麻煩。每當我輸入一個有效的登錄信息時,它不會打印任何東西(我正在打印它來檢查它是否有效),並且當我輸入一個無效的登錄信息時,它將打印會話,但登錄信息沒有任何價值。我還打印用戶名和密碼以檢查輸入是否正確。我是一般PHP新手和Web開發人員,非常感謝您的幫助!謝謝。用於登錄(PHP)的會話?
的PHP:
<?php
SESSION_START();
$servername = "localhost";
$username = "MY USERNAME";
$password = "MY PASSWORD";
$dbname = "MY USERNAME";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$username = $_POST['usernameinput'];
$password= $_POST['passwordinput'];
$_SESSION["loggedin"] = false ;
echo ($username);
echo ($password);
$result = mysqli_query($conn,"SELECT `user-id` FROM `users` WHERE `username` = '" . $username. "' AND `password` = '" . $password. "' ");
if (!$result) {
die(mysqli_error($conn));
}
if(mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_array($result);
return $row['ID'];
$_SESSION["loggedin"] = true;
}
print_r($_SESSION);
$conn->close();
?>
你可以好好解釋一下,返回$ row ['ID']是什麼?做? –
另外,爲什麼'返回'? –
http://php.net/manual/en/function.return.php *「如果從函數內部調用,則立即返回語句**結束當前函數的執行** ...」* –