I created a login with the classes but gives me an error

( ! ) Fatal error: Uncaught Error: Call to undefined method UserController::checkLogin() in C:\xampp\htdocs\progettoPersonale\controllers\User Controller.php on line 17

( ! ) Error: Call to undefined method UserController::checkLogin() in C:\xampp\htdocs\progettoPersonale\controllers\User Controller.php on line 17 Call Stack # Time Memory Function Location 1 0.0010 360312 {main}( ) ...\login.php:0 2 0.0030 384208 UserController->__construct( ) ...\login.php:7

the two classes are:

class UserController { public $username = ''; private $logged = false; private $usermodel = ''; public function __construct() { $this->usermodel = new UserModel(); session_start(); if ($_SERVER['REQUEST_METHOD']=='POST' && isset($_GET['action'])&& $_GET['action']== 'login' ){ $username = (isset($_POST['username']))? $_POST['username'] :false ; $password = (isset($_POST['password']))? $_POST['password'] :false ; var_dump($password,$username); if ($username !=false && $password !=false && $this->usermodel->checkLogin( $username, $password )){ $this->username =$username ; $this->logged = true ; $_SESSION['username']= $username ; $_SESSION['logged']= true ; $_SESSION[ 'message' ] = 'Login effettuato correttamente'; }else{ $_SESSION[ 'message' ] = 'Errore con il login; riprovare!'; } } elseif (isset($_GET['action'])&& $_GET['action']== 'logout'){ unset($_SESSION['username']); unset($_SESSION['logged']); $_SESSION[ 'message' ] = 'Logout effettuato correttamente'; } elseif (isset($_SESSION['username'])&& isset($_SESSION['logged'])){ $this->username = $_SESSION['username'] ; $this->logged = true ; } $this->redirectToProperArea(); } class UserModel { private $dbconn = null ; public function __construct() { $this->dbconn = new DbConnector(); } public function checkLogin($username, $password ){ $newpassword =password_hash($password, PASSWORD_DEFAULT); $res=$this->dbconn->select( array('id_utente'), 'iscritti', 'nome_utente='.$username.'&& password='.$newpassword ); $num_rows=$this->dbconn->num_rows($res); if ($num_rows ==1){ return true ; }else { return false ; } } } 
1

1 Answer

On line 17, you are calling UserController::checkLogin(), but the User Controller class has no method checkLogin. That function belongs to the UserModel class, so you must instead call UserModel::checkLogin()

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy