Jump to content

php & sql problem


diiazopde

Recommended Posts

hi i'm trying to create an app with php

but i have a real problem , i need help , please and thank you


// login.php
function  check_user_authentication(User $user)//return the user id if exist in data base else return false
    {
        require_once ('../app/models/loginDataBase.php');
        global $data_base_login;
        $request = $data_base_login->prepare('SELECT id FROM membres WHERE password= :password AND email = :email '); ///my problem is in this line
        $request->execute(array(
            'password' => $user->getPassword(),
            'email'=> $user->getEmail()
        ));
        $id_user = $request->fetch();
        $request->closeCursor();
        if ($id_user)
            return $id_user;
        else
            return false;
    }

//app/loginDataBase.php
   try
{
    $data_base_login = new PDO('mysql:host=localhost;dbname=espacemembre;charset=utf8', 'root','');
    $data_base_login->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
    die('Erreur : '.$e->getMessage());
}

the error is :Fatal error: Call to a member function prepare() on null in C:\xampp\htdocs\youMvc\app\models\Login.php on line 14

thanks every one

Link to comment
Share on other sites

Look at what the error message says. It says you're trying to call a method called prepare on a null value. So, in this line:

 

$data_base_login->prepare
$data_base_login has no value. You didn't show in that code where it gets defined.
Link to comment
Share on other sites

thanks ,

justsomeguy

the variable $data_base_login is defined in loginDataBase .php and i show it in the first post

 

//app/loginDataBase.php
try
{
$data_base_login = new PDO('mysql:host=localhost;dbname=espacemembre;charset=utf8', 'root','');
$data_base_login->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...