11.07.2015 Views

AJAX and PHP

AJAX and PHP

AJAX and PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4}{}$_POST['txtBthDay'] . '#' .$_POST['txtBthYear']))$_SESSION['errors']['txtBthYear'] = 'error';$errorsExist = 1;// Validate emailif (!$this->validateEmail($_POST['txtEmail'])){$_SESSION['errors']['txtEmail'] = 'error';$errorsExist = 1;}// Validate phoneif (!$this->validatePhone($_POST['txtPhone'])){$_SESSION['errors']['txtPhone'] = 'error';$errorsExist = 1;}// Validate read termsif (!isset($_POST['chkReadTerms']) ||!$this->validateReadTerms($_POST['chkReadTerms'])){$_SESSION['errors']['chkReadTerms'] = 'error';$_SESSION['values']['chkReadTerms'] = '';$errorsExist = 1;}// If no errors are found, point to a successful validation pageif ($errorsExist == 0){return 'allok.php';}else{// If errors are found, save current user inputforeach ($_POST as $key => $value){$_SESSION['values'][$key] = $_POST[$key];}return 'index.php';}// validate user name (must be empty, <strong>and</strong> must not be already registered)private function validateUserName($value){// trim <strong>and</strong> escape input value$value = $this->mMysqli->real_escape_string(trim($value));// empty user name is not validif ($value == null)return 0; // not valid// check if the username exists in the database$query = $this->mMysqli->query('SELECT user_name FROM users ' .'WHERE user_name="' . $value . '"');if ($this->mMysqli->affected_rows > 0)return '0'; // not validelsereturn '1'; // valid}// validate name137

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!