-2
我無法運行mysqli_num_rows
查詢。無法運行mysqli_num_rows
的if
聲明正在mysqli_query
但是當我着手mysqli_num_rows
其沒有工作,echo
的else
聲明。
我正在登錄系統上工作,只想驗證數據庫中是否存在電子郵件地址。
這裏是我的index.php:
<?php
include "connect.php";
include "functions.php";
$email = $password = "";
if(isset($_POST["submit"])){
$email = $_POST["email"];
$password = $_POST["password"];
}
echo $email .$password;
if (email_exist($conn,$email)) {
echo "success";
} else {
echo "failed";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Login Page</title>
</head>
<body>
<div class="login">
<form method="post" action="index.php">
<b>Email:</b><br>
<input type="text" name="email"><br><br>
<b>Password:</b><br>
<input type="text" name="password"><br><br><br>
<input type="submit" name="submit">
</form>
</div>
</body>
</html>
和functions.php中:
<?php
function email_exist($conn,$email){
$sql = "SELECT id FROM admin WHERE email = '$email'";
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows($result) == 1){
echo "Good work";
} else {
echo "dont";
}
}
?>
你爲什麼'== 1'? – user5173426
以確保只有1個結果在數據庫中用於該特定電子郵件。 –