daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Dec 6th, 2016 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. if(isset($_POST['submit']))
  3. {
  4.     if (empty($_POST["firstName"])) {
  5.         $Err[] = "* First Name is required";
  6.     } else {
  7.         $name = test_input($_POST["firstName"]);
  8.         // check if name only contains letters and whitespace
  9.         if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  10.             $Err[] = "Only letters are allowed in First Name";
  11.         }
  12.     }
  13.  
  14.     if (empty($_POST["email"])) {
  15.         $Err[] = "* Email is required";
  16.     } else {
  17.         $email = test_input($_POST["email"]);
  18.         // check if e-mail address syntax is valid
  19.         if (!preg_match("/([w-]+@[w-]+.[w-]+)/",$email)) {
  20.             $Err[] = "Invalid email format";
  21.         } else {
  22.             $emailSQL = "SELECT email FROM userdetails WHERE email = ?";
  23.             $SQ = $conn->prepare($emailSQL) or die("ERROR: " . implode(":", $conn->errorInfo()));
  24.  
  25.             $SQ->bindParam(1, $email);
  26.             $SQ->execute();
  27.             $result = $SQ->fetch();
  28.             if($result > 0) {
  29.                 $Err[] = "Sorry, email is already in use by another user";
  30.             }
  31.         }
  32.     }
  33.  
  34.     if (empty($_POST["surname"])) {
  35.         $Err[] = "* Surname is required";
  36.     } else {
  37.         $surname = test_input($_POST["surname"]);
  38.         // check if name only contains letters and whitespace
  39.         if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  40.             $Err[] = "Only letters are allowed in Surname";
  41.         }
  42.     }
  43.     if (empty($_POST["password"])) {
  44.         $Err[] = "* Password is required";
  45.     } else {
  46.         $password = test_input($_POST["password"]);
  47.     }
  48.     if (empty($_POST["userName"])) {
  49.         $Err[] = "* Username is required";
  50.     } else {
  51.         $username = test_input($_POST["userName"]);
  52.         // check if name only contains letters and whitespace
  53.         if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  54.             $Err[] = "Only letters are allowed in Username";
  55.         }
  56.     }
  57. }
  58. ?>
  59.    
  60. <form>Full name:&nbsp;
  61. <input type="text" name="name" /><span class="error" id="nameError"></span>;
  62. Email Address:
  63. <input id="emailCheck" type="text" name="email" /><span class="error" id="emailError">  
  64. </form>
  65.    
  66. //add in your connection to the database here, mine is just a require_once statement
  67. //get the passed parameter
  68. $email = mysql_real_escape_string(strtolower($_POST["email"]));
  69. //send a request to the database
  70. $sql = "SELECT email FROM your_dbtable_name WHERE LOWER(email) = '" . $email . "'";
  71. $result = mysql_query($sql, $conn) or die("Could not get email: " . mysql_error());
  72. if(mysql_num_rows($result) > 0) {
  73. //email is already taken
  74. echo 0;
  75. }
  76. else {
  77. //email is available
  78. echo 1;
  79. }
  80.    
  81. <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  82. $(document).ready(function() {
  83. //turns off autocomplete for browsers on email field
  84. $('#emailCheck').attr('autocomplete', 'off');
  85.  
  86. //listens for typing on the desired field
  87. $("#emailCheck").keyup(function() {
  88. //gets the value of the field
  89. var email = $("#emailCheck").val();
  90. //displays a loader while it is checking the database
  91. $("#emailError").html("<img alt="" src="../images/loader.gif" />");
  92. //here is where you send the desired data to the PHP file using ajax
  93. $.post("../php/checkavailability.php", {email:email},
  94. function(result) {
  95. if(result == 1) {
  96. //the email is available
  97. $("#emailError").html("Available");
  98. }
  99. else {
  100. //the email is not available
  101. $("#emailError").html("Email not available");
  102. }
  103. });
  104. }
  105. });
  106. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top