I'm new to PHP, trying to replicate a JavaBeans/JSF assignment...
I need to call a method in class Service that verify user name and password.
I have this php in the top of my index.php:
<?php
include("Service.php");
$service = new Service();
if($_POST) {
if (!$service->checkUser($_POST['name'], $_POST['password'])) {
$error = "Username and password incorrect";
echo $error;
}
}?>
Mu form action calls it's own document:
<form action="index.php" method="post">
I have 2 input fields (name, password) like this:
My Service.php class has the function checkUser. It returns a String:
public function checkUser($name, $password) {
foreach($this->users as $user) {
if ($user->getName() == $name && $user->getPassword() == $password) {
return "welcome.php";
}
else
return "error.php";
}
}
How can I use that String to use as navigation when form is submitted?