[英]php check if mysql select exists or empty
i'm trying to make a check to show content or not: 我正在尝试检查内容是否显示:
$stmt = $mysqli->prepare("SELECT *
FROM friends
WHERE friendID = ?
AND userID = ?");
$stmt->bind_param('ii', $id, $connectedUserID);
$stmt->execute();
if (login_check($mysqli) == true && $stmt->num_rows > 0) {
//do something
} else echo 'you are not allowed to be here';
I want to check if there's any row with those two ids. 我想检查是否有带有这两个ID的任何行。
But it's not working, i tried many different ways like using === or !== false. 但这不起作用,我尝试了许多不同的方法,例如使用===或!== false。
Any help? 有什么帮助吗?
Ty! 泰!
Try using a simple '=' or declare a boolean variable and set it 'true' and then compare 尝试使用简单的'='或声明一个布尔变量并将其设置为'true',然后进行比较
Also read: 另请阅读:
Most likely login check does not return true, the following should be enough 最有可能的登录检查未返回true,以下内容就足够了
if(isset($id, $connectedUserID)){
$stmt = $mysqli->prepare("SELECT *
FROM friends
WHERE friendID = ?
AND userID = ?");
$stmt->bind_param('ii', $id, $connectedUserID);
$stmt->execute();
$stmt->execute();
if ($stmt->num_rows > 0) {
//do something
} else{
echo 'you are not allowed to be here';
}
}else{
//redirect to login
}
If the user need to be logged in then this is not the place to check for that, it should be prior to this query. 如果用户需要登录,那么这里不是要检查的地方,它应该在此查询之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.