這裏是我的PHP登錄代碼,我有我的病情問題。我認爲。爲什麼我的PHP登錄代碼總是去到else語句,這是錯誤的用戶名和密碼?
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$mysql_database = "practiceLogin";
$conn = mysqli_connect($servername, $username, $password) or die ("Connection failed: " . mysqli_connect_error());
mysqli_select_db($conn,$mysql_database) or die("Opps some thing went wrong");
if (isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['Password'];
$stmt = $conn->prepare("SELECT * FROM tbl_account WHERE uName = ? AND uPassword = ?");
$stmt->bind_param('ss',$username,$password);
$stmt->execute();
$get_result=$stmt->get_result();
$row_count= $get_result->num_rows;
$stmt->close();
$conn->close();
if ($row_count>0){
$_SESSION['User_name'] = $username;
echo "Login Success!";
exit();
}else{
echo "Wrong username and password";
exit();
}
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action = "?" method = "POST">
<input type = "text" name="username"><br>
<input type = "password" name = "password"><br>
<input type = "submit" name = "submit" value = "Login"></br>
<a href = "register.php">Create Account</a>
</form>
</body>
</html>
每次我登錄到這一點,我經常去別的statment這是Wrong username and password
總是顯示出來,即使我有權利憑證?我錯過了什麼?
我不需要在這個時候哈希我的密碼,我只需要一個答案,如果我可以有一個成功的登錄頁面。謝謝
可能重複[PHP:「注意:未定義的變量」和「注意:未定義的索引」](http://stackoverflow.com/questions/4261133/ph p-notice-undefined-variable-and-notice-undefined-index) –
和這個問題是你的其他問題的轉貼http://stackoverflow.com/questions/38112958/why-my-php-code-is-not-工作的地方你犯了同樣的錯誤。 –
密碼應該散列。 – chris85