Advertisement
Guest User

Untitled

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