I'm trying to create a simple Login/Registration form using PHP/Html/MySql. I've successfully created the registration form (which submits to my Database), however i'm not quite sure on how to carry out the log in part. Below is what i've tried so far.
I have two Models in addition to my Database.php Model (holds db connection), Client Data.php, and ClientDataSet.php A login.php page and a login.phtml page.
ClientData.php is as follows:
<?php
require_once('Models/Database.php');
require_once ('Models/ClientDataSet.php');
class ClientData {
private $email, $password;
public function __construct($dbRow) {
$this->email = $dbRow['Email'];
$this->password = $dbRow['Password'];
}
public function getEmail() {
return $this->email;
}
public function getPassword() {
return $this->password;
}
}
ClientDataSet.php
<?php
require_once('Models/Database.php');
require_once ('Models/ClientData.php');
class ClientDataSet{
protected $_dbHandle, $_dbInstance;
public function __construct() {
$this->_dbInstance = Database::getInstance();
$this->_dbHandle = $this->_dbInstance->getdbConnection();
}
public function createClient($email, $password){
$sqlQuery='INSERT INTO mydatabase_Client (Email, Password,) VALUES ('. "'$email'".','. "'$password'".')';
//echo $sqlQuery;// useful check to see what Query has been created
$statement = $this->_dbHandle->prepare($sqlQuery); // prepare a PDO statement
$statement -> execute();
}
public function fetchClient($email, $password){
$sqlQuery='SELECT * FROM mydatabase_Client WHERE (Email='. "'$email'".', Password='. "'$password'".')';
//echo $sqlQuery;// useful check to see what Query has been created
$statement = $this->_dbHandle->prepare($sqlQuery); // prepare a PDO statement
$statement -> execute();
}
}
login.php
<?php
require_once('Models/Database.php');
require_once('Models/ClientData.php');
require_once('Models/ClientDataSet.php');
session_start();
$view = new stdClass();
$view->pageTitle ='Login';
if(isset($_POST['submit'])) {
$clientDataSet= new ClientDataSet();
$clientDataSet->fetchClient($_POST['Email'], $_POST['Password']);
} ?>
<?php
require_once('Views/login.phtml');
login.phtml
<?php require('template/header.phtml') ?>
<h3>Login Page</h3>
<p>If you have not already Registered. <a href="register.php">Register Here.</a></p>
<p><strong>Login</strong> using your <strong>email address</strong> and password.</p>
<table class="inputtable">
<tr>
<td class="label">Email:</td>
<td class="inputtd">
<input name="Email" type="email" class="standardwidth" /></td>
</tr>
<tr>
<td class="label">Password:</td>
<td class="inputtd">
<input name="Password" type="password" class="standardwidth" /></td>
</tr>
</table>
<div>
<input type="submit" value="Login" name="submit"/> <input type="reset" value="Reset" name="reset"/>
</div>