Advertisement
Guest User

Untitled

a guest
Dec 12th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. <?php
  2.  
  3. include "db.php";
  4.  
  5. // define variables and set to empty values
  6. $nameErr = $emailErr = $genderErr = $passwordErr = $cpasswordErr = "";
  7. $cpassword = "";
  8. $cust_email = $cust_username = $cust_password = $cust_fullname = $cust_country = $cust_dob = $cust_gender = $cust_phone ="";
  9.  
  10. if(isset($_POST["btnsignup"]))
  11. {
  12.  
  13. //Username Validation
  14. if (empty($_POST["txtcust_username"])) {
  15. $nameErr = "Name is required";
  16. } else {
  17. $cust_username = test_input($_POST["txtcust_username"]);
  18. // check if name only contains letters and whitespace
  19. if (!preg_match("/^[a-zA-Z ]*$/",$cust_username)) {
  20. $nameErr = "Only letters and white space allowed";
  21. }
  22. }
  23.  
  24. //Email Validation
  25. if (empty($_POST["txtcust_email"])) {
  26. $emailErr = "Email is required";
  27. } else {
  28. $cust_email = test_input($_POST["txtcust_email"]);
  29. // check if e-mail address is well-formed
  30. if (!filter_var($cust_email, FILTER_VALIDATE_EMAIL)) {
  31. $emailErr = "Invalid email format";
  32. }
  33. }
  34.  
  35. //Password Validation
  36. if(!empty($_POST["txtcust_password"]) && ($_POST["txtcust_password"] == $_POST["txtcust_cpassword"])) {
  37. $cust_password = test_input($_POST["txtcust_password"]);
  38. $cust_cpassword = test_input($_POST["txtcust_cpassword"]);
  39. if (strlen($_POST["txtcust_password"]) <= '6') {
  40. $passwordErr = "Your Password Must Contain At Least 6 Characters!";
  41. }
  42. elseif(!preg_match("#[0-9]+#",$cust_password)) {
  43. $passwordErr = "Your Password Must Contain At Least 1 Number!";
  44. }
  45. elseif(!preg_match("#[A-Z]+#",$cust_password)) {
  46. $passwordErr = "Your Password Must Contain At Least 1 Capital Letter!";
  47. }
  48. elseif(!preg_match("#[a-z]+#",$cust_password)) {
  49. $passwordErr = "Your Password Must Contain At Least 1 Lowercase Letter!";
  50. }
  51. }
  52. elseif(!empty($_POST["txtcust_password"])) {
  53. $cpasswordErr = "Please Check You've Entered Or Confirmed Your Password!";
  54. }
  55.  
  56. //Insert Into Table
  57. $insert = "INSERT INTO customer (cust_email,cust_username,cust_password,cust_fullname,cust_country,cust_dob,cust_gender,cust_phone)
  58. VALUES ('$cust_email','$cust_username','$cust_password','$cust_fullname','$cust_country','$cust_dob','$cust_gender','$cust_phone') ";
  59.  
  60. $run = mysqli_query($conn,$insert);
  61. if($run)
  62. {
  63. setcookie("Name",$cust_username);
  64. header("Location: home.php");
  65. }
  66. else
  67. echo "User has not been Add";
  68.  
  69. }
  70. function test_input($data) {
  71. $data = trim($data);
  72. $data = stripslashes($data);
  73. $data = htmlspecialchars($data);
  74. return $data;
  75. }
  76.  
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement