Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'extras/dbc.php';
- function register_user($first_name, $last_name, $email, $password, $password_repeat, $country, $city, $zip_code, $billing_address, $mobile_number, $dbh) {
- $first_name = trim($first_name);
- $last_name = trim($last_name);
- $email = trim($email);
- $password = trim($password);
- $country = trim($country);
- $city = trim($city);
- $zip_code = trim($zip_code);
- $billing_address = trim($billing_address);
- $mobile_number = trim($mobile_number);
- if (!preg_match('/^[a-z]+[a-z ]+[a-z]$/i', $first_name)) {
- $errors[] = 'Please, enter a valid first name which only contains letters.';
- }
- if (!preg_match('/^[a-z]+[a-z ]+[a-z]$/i', $last_name)) {
- $errors[] = 'Please, enter a valid first name which only contains letters.';
- }
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $errors[] = 'Enter a valid email.';
- }
- if ($password != $password_repeat) {
- $errors[] = 'Passwords do not match.';
- }
- if (empty($country)) {
- $errors[] = 'Select your country.';
- }
- if (!preg_match('/^[a-z]+[a-z ]+[a-z]$/i', $city)) {
- $errors[] = 'Enter a City with only letters.';
- }
- if (!is_numeric($zip_code)) {
- $errors[] = 'Zip code can only contain numbers.';
- }
- if (strlen($zip_code) > 5) {
- $errors[] = 'Zip code can only be 5 numbers long.';
- }
- if (!preg_match('/^[a-z]+[a-z0-9_]+[a-z0-9]$/i', $billing_address)) {
- $errors[] = 'Your billing address can only contain letters from a-z and numbers 0-9.';
- }
- if (!is_numeric($mobile_number)) {
- $errors[] = 'Mobile number can only contain numbers.';
- }
- if (!empty($errors)) {
- echo 'Please correct the following error(s):';
- foreach ($errors as $error) {
- printf ('<div class="error"><p class="red">%s</p></div>', $error);
- }
- }
- if (empty($errors)) {
- $register_query = $dbh->prepare("INSERT INTO users
- VALUES('',':first_name', ':last_name', ':email', ':password', ':country', ':city', ':zip_code', ':billing_address', ':mobile_number')");
- $register_query->bindParam(':first_name', $first_name, PDO::PARAM_STR);
- $register_query->bindParam(':last_name', $last_name, PDO::PARAM_STR);
- $register_query->bindParam(':email', $email, PDO::PARAM_STR);
- $register_query->bindParam(':password', $password, PDO::PARAM_STR);
- $register_query->bindParam(':country', $country, PDO::PARAM_STR);
- $register_query->bindParam(':city', $city, PDO::PARAM_STR);
- $register_query->bindParam(':zip_code', $zip_code, PDO::PARAM_INT);
- $register_query->bindParam(':billing_address', $billing_address, PDO::PARAM_STR);
- $register_query->bindParam(':mobile_number', $mobile_number, PDO::PARAM_INT);
- $register_query->execute();
- print_r($register_query);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement