Fatal error: Call to a member function prepare() on a non-object

Fermé
lovingun - 6 sept. 2016 à 17:50
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 - 7 sept. 2016 à 08:29
Hello i made a website and i have a problem in Login.php and Register.php !! It's the same.

PROBLEM IS IN THE LINE N°6 : Fatal error: Call to a member function prepare() on a non-object in /home/a7278696/public_html/login.php on line 111

    {
$errors[] = 'Please fill in all fields';
}

if (empty($errors))
{
$SQLCheckLogin = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username AND `password` = :password");
$SQLCheckLogin -> execute(array(':username' => $username, ':password' => SHA1($password)));
$countLogin = $SQLCheckLogin -> fetchColumn(0);
if ($countLogin == 1)
{
$SQLGetInfo = $odb -> prepare("SELECT `username`, `ID`, `status` FROM `users` WHERE `username` = :username AND `password` = :password");
$SQLGetInfo -> execute(array(':username' => $username, ':password' => SHA1($password)));
$userInfo = $SQLGetInfo -> fetch(PDO::FETCH_ASSOC);
if ($userInfo['status'] == "0")
{
$_SESSION['username'] = $userInfo['username'];
$_SESSION['ID'] = $userInfo['ID'];

$ip = getRealIpAddr();
$SQL = $odb -> prepare('INSERT INTO `loginlogs` VALUES(:username, :ip, UNIX_TIMESTAMP(), "")');
$SQL -> execute(array(':ip' => $ip, ':username' => $username));
echo '<div class="alert alert-success"><center><p><font color=\'black\'>Login Succeed. Redirecting....</font></p></center></div><meta http-equiv="refresh" content="3;url=index.php">';
die();


}

3 réponses

ThEBiShOp Messages postés 8378 Date d'inscription jeudi 22 mars 2007 Statut Contributeur Dernière intervention 8 février 2021 1 565
6 sept. 2016 à 17:58
Hello,

my guess is that your $odb object has not been properly instantiated...
I can't tell since you are not showing us where it came from.
0
just tell me what should i give you
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
7 sept. 2016 à 08:29
Bonjour

Montre nous le code de connexion à la bdd.

Active également si ce n'est pas déjà fait la gestion des erreurs pdo

https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs

Nb:tu es sur un site francophone. .. merci de ne pas y parler en anglais...



.
0