I have a problem with my code but I cannot solve it, I tried multiple things, but they did not work. Please if you can help me, tell me why rowCount() is always returning 0 even if I have a user with that name.
<?php
include("../api/config.php");
if(isset($_GET['user'],$_GET['key']) and !empty($_GET['user']) and !empty($_GET['key']))
{
$user = htmlspecialchars(urldecode($_GET['user']));
$key = htmlspecialchars($_GET['key']);
$bdd = new PDO('mysql: host = '.$dbhost.';dbname = '.$dbname.'', $dbusername, $dbpassword);
$requser = $bdd->prepare("SELECT * FROM users WHERE username = ? AND confirmkey = ?");
$requser->execute(array($user, $key));
$userexist = $requser->rowCount();
if($userexist==1)
{
$ufetch = $requser->fetch();
if($ufetch['isactive']==0)
{
$confirm_account = $bdd->prepare("UPDATE users SET isactive = 1 WHERE username = ? AND confirmkey = ?");
$confirm_account->execute(array($user, $key));
die('Congratulations! Your account was successfully confirmed. <a href="../?page=login">Login</a>');
sleep(3);
header("Location: ../?page=login");
$bdd = null;
$requser = null;
$confirm_account = null;
}
else
{
echo "This account has already been confirmed.";
$bdd = null;
$requser = null;
}
}
else
{
echo "User does not exist" . $userexist;
$bdd = null;
$requser = null;
}
}
else
{
die("Confirmation key or username is incorrect.");
}
?>