我正在使用PHP和Mysqli數據庫創建登錄頁面,我寫了查詢,但是mysqli_num_rows()在給定值時給了我一個錯誤。 PS:我在查詢這樣做在面向對象的格式mysqli_row_nums在查詢時不起作用
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "customerdb";
$connection = @new mysqli($host, $user, $pass, $db);
if ($connection->connect_errno) {
die("Connection failed!");
exit();
}
if (isset($_POST['submit'])) {
$username = $connection->real_escape_string($_POST['username']);
$password = $connection->real_escape_string($_POST['password']);
$script = "SELECT * FROM customer_management WHERE
customer_management.Username='".$username."'AND WHERE customer_management_Password='".$password."'";
$result = $connection->query($script, MYSQLI_USE_RESULT);
$check = $result->num_rows;
if ($check >= 1){
echo "Welcome to this website";
}
else{
echo"Sorry but your input is incorrect!";
}
}
?>
<!DCOTYPE html>
<html lang='en'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login Page</title>
</head>
<body>
<h1>Login Page</h1>
<form method="post" action="login.php">
<input type="text" placeholder = 'username' name="username" /><br /><br />
<input type="password" placeholder="password" name="password" /><br /><br />
<input type="submit" name="submit" value="Log In" />
</form>
</body>
</html>
旁註:這是不正確的<!DCOTYPE html>'如果這是你真正的代碼。 –
在查詢中有多個WHERE子句。刪除第二個。 – Marcus
檢查了這個錯誤........哦,別介意。只要RTM將雅? http://dev.mysql.com/doc/refman/5.7/en/where-optimizations.html並且不要使用純文本密碼;你肯定會完成的。 –