Advertisement
Guest User

Untitled

a guest
May 26th, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.51 KB | None | 0 0
  1. <?php
  2. include 'extras/dbc.php';
  3.  
  4. function register_user($first_name, $last_name, $email, $password, $password_repeat, $country, $city, $zip_code, $billing_address, $mobile_number, $dbh) {
  5.  
  6.         $first_name = trim($first_name);
  7.         $last_name = trim($last_name);
  8.         $email = trim($email);
  9.         $password = trim($password);
  10.         $country = trim($country);
  11.         $city = trim($city);
  12.         $zip_code = trim($zip_code);
  13.         $billing_address = trim($billing_address);
  14.         $mobile_number = trim($mobile_number);
  15.        
  16.         if (!preg_match('/^[a-z]+[a-z ]+[a-z]$/i', $first_name)) {
  17.                 $errors[] = 'Please, enter a valid first name which only contains letters.';
  18.         }
  19.        
  20.         if (!preg_match('/^[a-z]+[a-z ]+[a-z]$/i', $last_name)) {
  21.                 $errors[] = 'Please, enter a valid first name which only contains letters.';
  22.         }
  23.        
  24.         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  25.                 $errors[] = 'Enter a valid email.';
  26.         }
  27.        
  28.         if ($password != $password_repeat) {
  29.                 $errors[] = 'Passwords do not match.';
  30.         }
  31.        
  32.         if (empty($country)) {
  33.                 $errors[] = 'Select your country.';
  34.         }
  35.        
  36.         if (!preg_match('/^[a-z]+[a-z ]+[a-z]$/i', $city)) {
  37.                 $errors[] = 'Enter a City with only letters.';
  38.         }
  39.        
  40.         if (!is_numeric($zip_code)) {
  41.                 $errors[] = 'Zip code can only contain numbers.';
  42.         }
  43.        
  44.         if (strlen($zip_code) > 5) {
  45.                 $errors[] = 'Zip code can only be 5 numbers long.';
  46.         }
  47.        
  48.         if (!preg_match('/^[a-z]+[a-z0-9_]+[a-z0-9]$/i', $billing_address)) {
  49.                 $errors[] = 'Your billing address can only contain letters from a-z and numbers 0-9.';
  50.         }
  51.        
  52.         if (!is_numeric($mobile_number)) {
  53.                 $errors[] = 'Mobile number can only contain numbers.';
  54.         }
  55.        
  56.         if (!empty($errors)) {
  57.                 echo 'Please correct the following error(s):';
  58.                 foreach ($errors as $error) {
  59.                         printf ('<div class="error"><p class="red">%s</p></div>', $error);
  60.                 }
  61.         }
  62.        
  63.         if (empty($errors)) {
  64.                 $register_query = $dbh->prepare("INSERT INTO users
  65.               VALUES('',':first_name', ':last_name', ':email', ':password', ':country', ':city', ':zip_code', ':billing_address', ':mobile_number')");
  66.                                 $register_query->bindParam(':first_name', $first_name, PDO::PARAM_STR);
  67.                                 $register_query->bindParam(':last_name', $last_name, PDO::PARAM_STR);
  68.                                 $register_query->bindParam(':email', $email, PDO::PARAM_STR);
  69.                                 $register_query->bindParam(':password', $password, PDO::PARAM_STR);
  70.                                 $register_query->bindParam(':country', $country, PDO::PARAM_STR);
  71.                                 $register_query->bindParam(':city', $city, PDO::PARAM_STR);
  72.                                 $register_query->bindParam(':zip_code', $zip_code, PDO::PARAM_INT);
  73.                                 $register_query->bindParam(':billing_address', $billing_address, PDO::PARAM_STR);
  74.                                 $register_query->bindParam(':mobile_number', $mobile_number, PDO::PARAM_INT);
  75.                 $register_query->execute();
  76.                                 print_r($register_query);
  77.         }
  78. }
  79.  
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement