title: MVC php passing model to controller
body: <p>I have this login system, when I link the model to my controller, the controller can't get the variables of model which is $username, $password etc.
  How to properly way of handling this model and controller? I'm not using any framework just pure php and just following the mvc pattern.</p>
  
  <p>When I run the code it goes to Invalid Username or Password</p>
  
  <p>model</p>
  
  <pre><code>require_once("db.php");
  
  class loginModel{
  
      public function __construct(){
          $dbCon = new DbConnector();
          $this-&gt;dbCon = $dbCon-&gt;getConnection();
     }
  
      public function queryUser($username, $password){ // use parameters
          $username = mysqli_real_escape_string($this-&gt;dbCon, $username);
          $password = mysqli_real_escape_string($this-&gt;dbCon, sha1($password));
          $empty = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
  
          $myQuery = "SELECT * FROM login WHERE username = '".$username."' and password = '".$password."'";
          $results = $this-&gt;dbCon-&gt;query($myQuery);
          return $results-&gt;fetch_array(); // return the result 
  
          if(empty($username) or $password == $empty){
              return "Username or Password is empty";
          }elseif($username == $row['username'] and $password == $row['password']){
          if($results-&gt;num_rows == 1){
              session_start();
              $_SESSION['user'] = $username;
              header('Location: ../view/index.php');
          }else{
              return "Login Unsuccessful";
          }
          }else{
              return "Invalid Username or Password";
          }
      }
  </code></pre>
  
  <p>}</p>
  
  <p>controller</p>
  
  <pre><code>require_once("../model/loginModel.php");
  
  class loginController{
      public $loginModel;
      public function __construct(){  
      $loginModel = new loginModel(); // create object of model
  }
  
      public function select(){
          $userData = $this-&gt;loginModel-&gt;queryUser($_POST['username'], $_POST['password']);
  
          if($userData) {
              session_start();
              $_SESSION['user'] = $userData;
              header('Location: ../view/index.php');
          } else {
              return "Invalid Username or Password";
          }
     }
  }
  $loginController = new loginController();
  $loginController-&gt;select();
  </code></pre>