我試過這段代碼,它似乎沒有工作,所以我會很感激,如果有人可以幫我解決任何錯誤。用戶名和密碼驗證PHP MySql
簡要概述,我的數據庫根目錄是'localhost',數據庫名'ee2800'密碼'secret',我需要它來驗證用戶名和密碼。
以下是我似乎沒有工作。
<?php
$conn = new mysqli("localhost", "ee2800", "secret", "ee2800");
if (mysqli_connect_errno()) {
echo "Connection Failed. Try again." . mysqli_connect_error();
exit();
} /* else {
echo "Connection Successful <br/> ";
} */
// Connect to database server
mysql_connect("localhost", "ee2800", "secret") or die(mysql_error());
$UserName = mysql_real_escape_string($_POST['UserName']);
$Password = mysql_real_escape_string($_POST['Password']);
$sql = "SELECT * FROM users WHERE UserName = '$UserName' AND Password = '$Password' ";
$result = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($result);
if ($numrows > 1) {
else if ($numrows = 0) {
echo "wrong username or password"
} else {
echo "welcome"
}
// Close the database connection
mysql_close();
?>
謝謝
**注:**你混合'mysqli_ *'和'mysql_ *'功能。 –
也許你在'if($ numrows> 1)'塊中忘記了分號? –
順便說一下,'$ conn = new mysqli(「localhost」,「ee2800」,「secret」,「ee2800」); .... echo「Connection Successful
」; } * /'在這段代碼中完全沒用。 –