Advertisement
michaelyuen

Untitled

Apr 1st, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.83 KB | None | 0 0
  1. <?php
  2. // require_once("connection.php");
  3. // session_start();
  4. // define variables and set to empty values
  5.  
  6. $clientFirstName = $clientLastName = $clientEmail = $clientPassword = $clientCPassword = $clientContact = "";
  7.  
  8. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  9.    
  10.     // First Name Validation
  11.     if (empty($_POST["clientFirstName"])) {
  12.        
  13.         die("error: empty field");
  14.     } else {
  15.         $clientFirstName = test_input($_POST["clientFirstName"]);
  16.         // check if name only contains letters and whitespace
  17.         if (!preg_match("/[a-zA-Z ]/", $clientFirstName)) {
  18.            
  19.             die("Error: Only letters and white space allowed");
  20.            
  21.         }
  22.     }
  23.    
  24.     // Last Name Validation
  25.    
  26.     if (empty($_POST["clientLastName"])) {
  27.        
  28.         die("error: empty field");
  29.        
  30.     } else {
  31.        
  32.         $clientLastName = test_input($_POST["clientLastName"]);
  33.        
  34.         // check if name only contains letters and whitespace
  35.        
  36.         if (!preg_match("/[a-zA-Z ]/", $clientLastName)) {
  37.            
  38.            
  39.             die("Error: Only letters and white space allowed");
  40.         }
  41.        
  42.     }
  43.  
  44.    
  45.     // Email Validation
  46.    
  47.     if (empty($_POST["clientEmail"])) {
  48.        
  49.         die("error: empty field");
  50.        
  51.     } else {
  52.        
  53.         $clientEmail = test_input($_POST["clientEmail"]);
  54.        
  55.         // check if e-mail address is well-formed
  56.        
  57.         if (!filter_var($clientEmail, FILTER_VALIDATE_EMAIL)) {
  58.            
  59.             die("Error: Invalid email format");
  60.            
  61.         }
  62.        
  63.     }
  64.    
  65.    
  66.     // Password Validation
  67.    
  68.     if (empty($_POST["clientPassword"])) {  
  69.        
  70.         die("error: empty field");
  71.        
  72.     }
  73.    
  74.    
  75.     // Confirm Password Validation
  76.    
  77.     if (empty($_POST["clientCPassword"])) {
  78.          
  79.         die("error: empty field");
  80.        
  81.     }
  82.    
  83.    
  84.     if ($clientPassword != $clientCPassword) {
  85.        
  86.         die("error: passwords mismatch");
  87.        
  88.        
  89.     } else {
  90.        
  91.         $hashedClientPassword = password_hash($clientPassword, PASSWORD_DEFAULT);
  92.              
  93.     }
  94.    
  95.    
  96.     if (empty($_POST["clientContact"])) {
  97.        
  98.        
  99.         die("error: empty field");
  100.        
  101.     } else {
  102.        
  103.         $clientContact = test_input($_POST["clientContact"]);
  104.        
  105.         // check if number is correct
  106.        
  107.         if (!preg_match("/[0-9]/", $clientContact)) {
  108.            
  109.             die("error: Only 0-9 allowed");
  110.         }
  111.        
  112.     }
  113.        
  114.         echo 'All Passed';
  115.    
  116.     // $check_email = $conn->query("SELECT clientEmail FROM tbl_clients WHERE clientEmail='$clientEmail'");
  117.    
  118.     // $emailCount = $check_email->num_rows;
  119.    
  120.    
  121.     // if ($emailCount == 0) {
  122.        
  123.         // $newClient = "INSERT INTO tbl_clients(clientFirstName, clientLastName, clientEmail, clientPassword, clientContact) VALUES('$clientFirstName','$clientLastName','$clientEmail','$hashedClientPassword','$clientContact')";
  124.        
  125.         // if ($newClient === false) {
  126.            
  127.             // $result   = array();
  128.             // $result[] = array(
  129.                 // "status" => "Error"
  130.             // );
  131.         // } else {
  132.             // echo "Your have been signed up - please now Log In";
  133.            
  134.             // $result   = array();
  135.             // $result[] = array(
  136.                 // "First Name" => $clientFirstName,
  137.                 // "Last Name" => $clientLastName,
  138.                 // "Email" => $clientEmail,
  139.                 // "Password" => $hashedClientPassword,
  140.                 // "Contact" => $clientContact,
  141.                 // "status" => "success"
  142.             // );
  143.            
  144.         // }  
  145.        
  146.     // } else {
  147.        
  148.         // echo "Already Exists";
  149.         // $result   = array();
  150.         // $result[] = array(
  151.             // "status" => "Error"
  152.         // );
  153.        
  154.        
  155.     // }
  156.    
  157.     // echo json_encode($result);
  158.    
  159. }
  160.  
  161. function test_input($data)
  162. {
  163.    
  164.     $data = trim($data);
  165.    
  166.     $data = stripslashes($data);
  167.    
  168.     $data = htmlspecialchars($data);
  169.    
  170.     return $data;
  171.    
  172. }
  173.  
  174. ?>
  175. <!DOCTYPE HTML>  
  176. <html>
  177. <head>
  178.  
  179. </head>
  180. <body>  
  181.  
  182. <h2>Reg User</h2>
  183. <form method="post" action="">
  184.       <label>
  185.         First Name:<input type="text" name="clientFirstName"><br/>
  186.         Last Name:<input type="text" name="clientLastName"><br/>
  187.         Email:<input type="text" name="clientEmail"><br/>
  188.         Password:<input type="password" name="clientPassword"><br/>
  189.         Confirm Password:<input type="password" name="clientCPassword"><br/>
  190.         Contact:<input type="text" name="clientContact"><br/>
  191.         <input type="submit" value="Register" name="submit">
  192.       </label>
  193.     </form>
  194.  
  195. </body>
  196. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement