<?php
include_once("checklogin.php");
$u = "";
if(isset($_GET["u"])){
$u = preg_replace('#[^a-z0-9]#i', '', $_GET['u']);
} else {
header("location: http://www.myswesite.com/login.php");
exit();
}
$sql = "SELECT * FROM users WHERE username='$u' AND activated='1' LIMIT 1";
$user_query = mysqli_query($connection, $sql);
$numrows = mysqli_num_rows($user_query);
if($numrows < 1){
echo "User does not exist or is not yet activated, press back";
exit();
}
?>
答案 0 :(得分:5)
您必须先使用 store_result 缓冲结果集,然后才能获取num行。
$user_query = mysqli_query($connection, $sql);
mysqli_store_result($connection);
$numrows = mysqli_num_rows($user_query);
请参阅http://www.php.net/manual/en/mysqli-result.num-rows.php:
对于无缓冲的结果集,mysqli_num_rows()将不会返回正确的行数,直到检索到结果中的所有行为止。
答案 1 :(得分:1)
我认为当你传递用户名时你的查询中存在语法错误试试这个我认为它适合你。
$username=$_SESSION['username'];
SELECT * FROM tbl_users WHERE Username='".$username."'