narjis Posted February 16, 2011 Share Posted February 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227841-unable-to-count-number-of-rows/ Share on other sites More sharing options...
gristoi Posted February 16, 2011 Share Posted February 16, 2011 So, do you have three rows in your table with identical username and password ? Quote Link to comment https://forums.phpfreaks.com/topic/227841-unable-to-count-number-of-rows/#findComment-1174889 Share on other sites More sharing options...
narjis Posted February 16, 2011 Author Share Posted February 16, 2011 no Quote Link to comment https://forums.phpfreaks.com/topic/227841-unable-to-count-number-of-rows/#findComment-1174895 Share on other sites More sharing options...
gristoi Posted February 16, 2011 Share Posted February 16, 2011 You query is looking for records where the usename and password match the ones passed into it, so if you only have one record where the username and password match you will only return 1 row. Why were you expecting 3 rows to be returned? Quote Link to comment https://forums.phpfreaks.com/topic/227841-unable-to-count-number-of-rows/#findComment-1174903 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.