本文介紹了mysqli_query() 總是返回真的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
這是我的表格:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="register_ajax.php" method="get">
<input type="text" name="email">
<input type="submit" value="test">
</form>
</body>
</html>
這是我的php代碼:
<?php
$dbc = mysqli_connect("localhost","root","*******","continental_tourism") OR die(mysqli_connect_error());
$email = $_GET['email'];
$query = "SELECT email FROM customer_info WHERE email = '$email' ";
$r = mysqli_query($dbc, $query) OR die(mysqli_error($dbc));
if($r)
echo "Email address exists!";
else
echo "sss";
?>
如果我輸入正確的(db 上的現有電子郵件)$r
為真.但是如果我輸入不存在的電子郵件,那么 $r
也是如此.這是為什么?基本上我想檢測空集.我該怎么做?
If I enter a correct(Existing email on db) $r
is true. But if I enter non existing email, then also $r
is true. Why is that? Basically I want to detect the empty set. How can I do it?
謝謝!
推薦答案
$r
只有在出現 SQL 錯誤時才會為假.否則它將始終返回一個對象,即使您的 SELECT 語句沒有返回任何行.
$r
will only be false if there was SQL error. Otherwise it will always return an object, even if no rows are returned by your SELECT statement.
使用mysqli_num_rows()
計算返回的行數.零表示沒有人使用該電子郵件地址.
Use mysqli_num_rows()
to count how many rows are returned. Zero means no one is using that email address.
if(mysqli_num_rows($r))
echo "Email address exists!";
else
echo "sss";
這篇關于mysqli_query() 總是返回真的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!