Hello everyone.

I am trying to make a simple to-do list program using PHP and the MVC pattern. I have managed to make the login page, the model and the controller for managing logins. It is working properly because it can discern if the user exists or not. After validating the user, it includes another page using require_once(). The problem is that it is displaying the contents of the new page (the one you see after loggin in) right below the login form instead of simply replacing the whole page with the new one. Here is the code. It is located in the index.php page:

<?php

include 'model/user_model.php';
include 'controller/user_controller.php';
include 'view/user_view.php';


$usermodel = new UserModel();
$usercontroller = new UserController($usermodel);
$userview = new UserView($usercontroller, $usermodel);

if(!isset($_SESSION)) {
  $userview->outputlogin();
}

if(isset($_REQUEST['name'],$_REQUEST['password'])) {


    if ($usercontroller->validateuser($_REQUEST['name'],$_REQUEST['password'])) {

        $userview->outputlogged();

    }else {
        $userview->outputlogin();
        echo "<p>Wrong user or password</p>";
    }

}


?>

the outputlogged() function does this:

 public function outputlogged() {

        require_once($this->usermodel->template['logged']);
        }
}

It simply outputs the logged.php page which currently only says "You logged in". The problem is that the message is appearing BELOW the login form instead of simply replacing the whole page with the one with the message. What am I doing wrong?

require parse the php code and add output not replace if you follow the flow of your code it may be right.

Small correction: disregard the last curly brace. It doesn't belong there (and I don't know how to edit my post anymore...)

Thanks for your response. Could do please be more specific? What do you mean by "require parse"? How do you add the content (could you please give me a snippet)??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.