rowLogin
is always returning 0
? but when i run the query on sql i get the correct outcome! I've had a look at loads of solutions but literally none are working.
$queryLogin =("SELECT count(*) as count FROM `tblUser` WHERE `username` = '$username' and `password` ='$password'");
$resultLogin = $mysqli->query($queryLogin);
$rowLogin = $resultLogin->fetch_assoc();
echo $rowLogin['count']." rows in table tblUser.";
Your code is not very good...
You really need to be using MYSQLi prepared statements esp with username / pass checks...
$mysqli = new mysqli(...);
$query = "SELECT count(*) as count FROM `tblUser` WHERE `username`=? and `password`=?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('ss',$username,$password);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows){
$row = $result->fetch_assoc();
echo $row['count'] . " rows in table tblUser.";
}
I understand you are potentially looking into just getting some information, but this is the best route to take so move this way. Do not continue in your path.
It is very likely that your query failed because you have ( )
around your actually query. So if you want to use that just get rid of the ( )
on the line with $queryLogin
.
You don't need scopes.
$queryLogin = "SELECT count(*) as count FROM `tblUser` WHERE `username` = '$username' and `password` ='$password'";
$resultLogin = $mysqli->query($queryLogin);
$rowLogin = $resultLogin->fetch_assoc();
echo $rowLogin['count']." rows in table tblUser.";
Only use scope in inline query.
You already using scopes here...
$resultLogin = $mysqli->query($queryLogin);