diiazopde Posted January 28, 2016 Share Posted January 28, 2016 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 More sharing options...
davej Posted January 28, 2016 Share Posted January 28, 2016 Where do you bind your values? http://www.w3schools.com/php/php_mysql_prepared_statements.asp http://lmgtfy.com/?q=pdo+sql+example Link to comment Share on other sites More sharing options...
diiazopde Posted January 28, 2016 Author Share Posted January 28, 2016 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted January 28, 2016 Share Posted January 28, 2016 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 More sharing options...
diiazopde Posted January 28, 2016 Author Share Posted January 28, 2016 thanks , justsomeguy the variable $data_base_login is defined in loginDataBase .php and i show it in the first post //app/loginDataBase.phptry{$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 More sharing options...
justsomeguy Posted January 28, 2016 Share Posted January 28, 2016 Are you defining that variable globally? Trust the error message. It says you're trying to use a global variable that is not defined. Link to comment Share on other sites More sharing options...
diiazopde Posted January 28, 2016 Author Share Posted January 28, 2016 (edited) ok , thanks man , i found the problem it was about including the file with wrong way , Thanks appreciate it Edited January 28, 2016 by diiazopde Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now