-1

I am a beginner in PHP. when I try to do mysql_num_rows it is giving an error:

Warning: mysql_num_rows() expects parameter 1 to be resource, object given in D:\xampp\htdocs\kcp\police\viewcase.php on line 22

This is the code:

<?php
session_start();
if(empty($_SESSION['pusername'])||empty($_SESSION['pid']))
{
    header('location://localhost/kcp/police_login.html');
    exit();

}
else
{
    $station=$_SESSION['station'];
    $con = mysqli_connect('localhost','root','','kcp');

    if(!$con)
    {
        echo 'NOT CONNECTED TO DB';
    }
    $sql="SELECT * FROM complaint WHERE station='$station'";
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    $res=mysqli_query($con,$sql) or die("llllllll");

    $numrow=mysql_num_rows($res);
    echo $numrow;
}

?>
tausun
  • 2,154
  • 2
  • 24
  • 36
Akram Ashraf
  • 1
  • 1
  • 8
  • 1
    If you use the `mysqli` object-oriented interface these mistakes are pretty much impossible, a single missing `i` won't tank your code. The procedural style was intended for compatibility with PHP 4, which is now long dead. Even better, use PDO which is not MySQL specific and generally all-around easier to use. – tadman Mar 15 '17 at 04:05

2 Answers2

5

You can't mix up mysql and mysqli.

$numrow = mysqli_num_rows($res);
echo $numrow;

mysqli_num_rows() Reference

Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32
0

Use mysqli_num_rows instead of mysql_num_rows

Oops
  • 1,373
  • 3
  • 16
  • 46