I'm stucked
Posted: Mon Jun 27, 2011 3:13 am
When i press the register button and username & password are empty there should appear an error message saying "Please fill in all fields"
But i dont know why doesn't works can anyone take a look please?
But i dont know why doesn't works can anyone take a look please?
Code: Select all
<?php
error_reporting(E_ALL);
class register
{
private $_username;
private $_password;
private $_password2;
private $_passmd5;
private $_mail;
private $_register;
private $_token;
private $_errors;
public function __construct()
{
$this->_register = isset($_POST['register'])? 1 : 0;
if(isset($_POST['register']))
{
$this->_username = $this->filter($_POST['username']);
$this->_password = $this->filter($_POST['password']);
$this->_password2 = $_POST['password2'];
$this->_mail = $this->filter($_POST['mail']);
$this->_token = $_POST['token'];
}
$this->_errors = array();
}
public function filter($var)
{
return preg_replace('/[^a-zA-Z0-9]/','',$var);
}
public function register()
{
if($this->allfields())
{
}
else
$this->showerrors();
}
public function allfields()
{
if(isset($this->_username) && isset($this->_password))
{
return true;
}
else
return false;
}
public function messages()
{
try{
if(!$this->allfields())
throw new Exception("Please fill in all fields!");
}
catch(Exception $e)
{
$this->_errors[] = $e->getMessage();
}
}
public function showerrors()
{
foreach ($this->_errors as $key=>$value) {
echo $value."<br>";
}
}
}
?>