如果“查询结果为= 1”,我应该更换“代码验证?”
我尝试了很多使用num_rows的方法,但它不起作用。
我的PHP代码:
$con=mysqli_connect("localhost","mbrconsu_un394x","y1cz9,rd+hf6","mbrconsu_mmx");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$usuario = $con->real_escape_string($_GET['usuario']);
$senha = $con->real_escape_string($_GET['senha']);
$query = mysqli_query($con, "SELECT * FROM 'login' WHERE usuario = '$usuario' AND senha='$senha'");
if(CODE TO VERIFY IF QUERY RESULT ROW IS = 1){
while($row = mysqli_fetch_assoc($query)){
$db_username = $row['usuario'];
$db_password = $row['senha'];
}
if($usuario == $db_username && $senha == $db_password){
return true;
}
} else {
return false;
}
mysqli_close($con);
?>
答案 0 :(得分:24)
$query->num_rows;
或
mysqli_num_rows($query);
答案 1 :(得分:2)
您也可以使用此SQL查询:
Select count(*) from table
答案 2 :(得分:2)
你可以做到
with
您也可能希望将用户名和密码保存在一个文件中作为常量
答案 3 :(得分:-2)
您可以使用:
$stmt=$mysqli->prepare("select `id` from `agahicustomer` where `city`=?");
$stmt->bind_param("s",$cityid);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id);
return $stmt->affected_rows;
$stmt->close();