Jump to content

unable to count number of rows


narjis

Recommended Posts

I am using mysqli to open the database table and execute query. The qery is running successfully, but the number of rows count is not giving correct results.

$username=$_POST['username'];
    $pass=$_POST['password'];
    $mysql = mysqli_connect("localhost","root","","auth");
    $sql="SELECT * FROM 'authorized_users' WHERE name = '".$username ."' AND password  = '"
    . $pass. "'"; 
   // print "$username $password";
    if(!$mysql){echo "cannot connect to databse" ;
    }
    else
    {
    echo "Connected";
    $result = $mysql->query($sql);

    $row = $result->num_rows;
    echo "Found \$rows ". $row;
    for($i=0;$i<$row;$i++){
    echo "found a record at ".$i;
    } 
    $result->close();
    } 
    $mysql->close();  

This should return 3 rows but it gives 1 only.

Link to comment
https://forums.phpfreaks.com/topic/227841-unable-to-count-number-of-rows/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.