query('SELECT * FROM andmed'); // //while ($row = mysql_fetch_object($db->getResult())) { // echo $row->username . '
'; //} //$conn = mysql_connect('localhost', 'root', ''); //mysql_select_db('test'); // //$query = 'SELECT username, email FROM andmed'; //$result = mysql_query($query); // //while ($row = mysql_fetch_object($result)) { // echo $row->username . ' '. $row->email .'
'; //} // //mysql_close($conn); class Error { private $errors = array(); private $data = array(); public function __construct() { $this->getPOSTdata(); } /** * Checks if there is errors * * @return true if there is no errors */ public function isErrors() { if (sizeof($this->errors) > 0) { return true; } } /** * Sets error on field * * @param field $field * @param error $error */ public function setError($field, $error) { $this->errors[$field] = $error; } /** * Returns data from $this->data variable * * @return unknown */ public function getData() { return $this->data; } /** * Returns errors from var $this->errors * * @return unknown */ public function getErrors() { return $this->errors; } /** * Gets the $_POST data and sets to local object variablese * */ public function getPOSTdata() { foreach ($_POST as $field => $value) { $this->__set($field, $value); } } public function __set($field, $value) { $this->data[$field] = $value; } public function __get($field) { if (array_key_exists($field, $this->data)) { return $this->data[$field]; } } public function __destruct() { unset($this->errors); } } if (isset($_POST['post'])) { $val = new Error(); //print_r($val->getData()); if ($val->name == '') { $val->setError('Name', 'field is empty!'); } if ($val->email == '') { $val->setError('Email', ' field is empty!'); } if (!$val->isErrors()) { echo 'We have here success!'; } else { foreach ($val->getErrors() as $key => $value) { echo $key .' : '. $value .'
'; } } } ?>