I am trying to create a simple validation class for my registration form. I am having great difficulty with my logic (among some things). I can't get to "count" the variable to do as I want. I am basically using the function countErrors () to check and see if there were any errors incurred. Thanks for any help you can offer... I know it's a mess.
PHP Code:class ValidateReg {
var $db;
var $errors;
var $count;
function ValidateReg (&$db) {
$this->db=& $db;
$this->errors= " ";
$this->count= 0;
}
function username ($username = " ") {
if ( $username == " " )
return false;
else
return true;
}
function uniquename ($username = " ") {
$sql = "SELECT * FROM
".person."
WHERE
".username."='".$username."'";
$result = $this->db->query($sql);
if ( $result->size() > 0 )
return false;
else
return true;
}
function displayErrors () {
if ( !$this->username () ) {
$this->errors = '<strong>Username required!</strong><br />';
$this->count++;
}
if ( !$this->uniquename () ) {
$this->errors .= '<strong>Username already registered!</strong>';
$this->count++;
}
echo $this->errors;
}
function countErrors () {
if ($this->count > 0)
return false;
else
return true;
}
}





Bookmarks