doujiao1180 2014-10-31 16:56
浏览 97
已采纳

MYSQLI_NUM_ROWS不返回任何内容[关闭]

I have a table called "users" with 1 row. I have been trying to get the number of rows that exist when the username and password have been entered. This wasn't returning anything, so I have created this code in the most simple form, but still it is not returning anything.

If I run the query on phpmyadmin, it returns the row.

Why could this not be working?

include("../includes/db.php");
$result = $link->query("SELECT * FROM users");
die(mysqli_num_rows($result));

The connection to the database is fine, all the other code works fine on my CMS.

edit:

This is my now working code:

include("../includes/db.php");
if(!isset($_SESSION['loggedin'])){
    if(isset($_POST['username'])){
        $username = $_POST['username'];
        $password = md5($_POST['password']);
        $sql = "SELECT * from users WHERE username LIKE '{$username}' AND password LIKE '{$password}' LIMIT 1";
        $result = $link->query($sql);
        if (!$result->num_rows == 1) {
            echo "<p>Invalid username/password combination</p>";
            LoginForm();
        } else {
            echo "<p>Logged in successfully</p>";
            $_SESSION['loggedin'] = 1;
        }
    }else{
        LoginForm();
    }
} 
  • 写回答

1条回答 默认 最新

  • doudong0425 2014-10-31 17:00
    关注
    include("../includes/db.php");
    $result = $link->query("SELECT * FROM users");
    echo $result->num_rows;
    

    My bad for the previous answer. It's been a while since I've used PHP

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?