Jump to content
Sign in to follow this  
diiazopde

php & sql problem

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

Share this post


Link to post
Share on other sites

thanks for responding , actually i'm trying to implement the MVC desgin patterns , this variables will be bind in a file which exit in the controllers directory

thank you again

Share this post


Link to post
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.

Share this post


Link to post
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());
}

Share this post


Link to post
Share on other sites

Are you defining that variable globally? Trust the error message. It says you're trying to use a global variable that is not defined.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...