ı have a problem my login page. I got this error: Fatal error: Uncaught Error: Call to a member function RowCount() on bool in C:\\xampp\\htdocs\\root\\login.php:43 Stack trace: #0 {main} thrown in C:\\xampp\\htdocs\\root\\login.php on line 43
<?php
if(isset($_POST['loginRequest'])){
$username = $_POST['email'];
$password = $_POST['password'];
$Sifreli = md5($password);
$query = $db->query("SELECT * FROM yonetim WHERE username = '{$username}'")->fetch(PDO::FETCH_ASSOC);
if($say = $query->RowCount()){
if ($say > 0){
$user = $query;
if($user['pass'] == $Sifreli){
$_SESSION['LOGGED'] = $user['username'];
if(isset($_SESSION['LOGGED'])){
header('location:index.php');
}
} else {
echo "Kullanıcı adı veya şifre hatalı!";
}
} else {
echo 'Böyle bir kullanıcı bulunmamaktadır.';
}
}
}
?>
rowCount()
is the most useless method in all database APIs. And your code is a perfect example of that.
You already have your database results in $query, it means you don't need anything else . Just get rid of the rowCount
line and use $query
right in the condition:
$query = $db->query("SELECT * FROM yonetim WHERE ...")->fetch(PDO::FETCH_ASSOC);
if ($query){
Two obligatory notes:
Here is a canonical example I wrote for the code to check the login and password using PDO :
$stmt = $pdo->prepare("SELECT * FROM yonetim WHERE username = ?");
$stmt->execute([$username]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password']))
{
$_SESSION['LOGGED'] = $user['username'];
header('location:index.php');
exit;
} else {
echo "Kullanıcı adı veya şifre hatalı!";
}
see - it's much simpler actually than your current code!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.