MYSQLI_NUM_ROWS 总是返回 0 [英] MYSQLI_NUM_ROWS ALWAYS RETURNING 0

查看:42
本文介绍了MYSQLI_NUM_ROWS 总是返回 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图尽快摆脱一个错误.我正在使用 mysql_num_rows 但它总是返回 0.我不知道这是因为我的语法错误还是什么......你们能帮我吗?这是代码;

i'm trying to get rid of a bug ASAP. I'm using mysql_num_rows but it ALWAYS returns 0. And i dont know if it's because i have the wrong syntax or what... can you guys help me? here's the code;

<?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(); 
}
?>

推荐答案

我认为当您传递用户名时查询中存在语法错误试试这个我认为它适合您.

i think there is a syntax error in your query when you are passing username try this i think it works for you.

$username=$_SESSION['username'];
   SELECT * FROM tbl_users WHERE Username='".$username."'

这篇关于MYSQLI_NUM_ROWS 总是返回 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆