Advertisement
Guest User

Untitled

a guest
Jul 16th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. <form name="myForm" id="myForm" action="includes/user-signup.php"method="post">
  2. <input id="signup-username" type="text" required pattern="[a-zA-Z].{2,}" name="username" placeholder="Username">
  3. <input id="signup-pwd" type="password" name="pwd" required pattern="(?=.*d)(?=.*[a-z]).{9,}" title="Password must contain at least 9 characters, including numbers." placeholder="Password">
  4. <input id="signup-email" type="text" name="email" required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,3}$" placeholder="Email">
  5. <input id="signup-submit" type="submit" name="submit" value="SING UP" class="btn-login">
  6. </form>
  7.  
  8. if (isset($_POST['submit'])){
  9. include_once 'dbh.inc.php';
  10.  
  11. $username = mysqli_real_escape_string($conn, $_POST['username']);
  12. $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
  13. $email = mysqli_real_escape_string($conn, $_POST['email']);
  14.  
  15. if(empty($username) || empty($pwd) || empty($email)){
  16. echo "Fill in all Fields!";
  17. }else {
  18. if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
  19. echo "Email is invalid!";
  20. }else{
  21. $stmt = $conn->prepare("SELECT * FROM users WHERE username=?");
  22. $stmt->bind_param("s", $uid);
  23. $uid = $username;
  24. $stmt->execute();
  25. $result = $stmt->get_result();
  26. $usernamecheck = mysqli_num_rows($result);
  27. $rowNum = $result->num_rows;
  28. if($rowNum > 0){
  29. echo "Username is taken!";
  30. }else{
  31. $stmt = $conn->prepare("SELECT * FROM users WHERE email=?");
  32. $stmt->bind_param("s", $uemail);
  33. $uemail = $email;
  34. $stmt->execute();
  35. $result = $stmt->get_result();
  36. $usernamecheck = mysqli_num_rows($result);
  37. $rowNum = $result->num_rows;
  38. if($rowNum > 0){
  39. echo "Email is taken";
  40. }else{
  41. $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
  42. $stmt = $conn->prepare("INSERT INTO users (username, pwd, email) VALUES (?, ?, ?)");
  43. $stmt->bind_param("sss",$uid, $password, $theemail);
  44. $uid = $username;
  45. $password = $hashedPwd;
  46. $theemail= $email;
  47. $stmt->execute();
  48. $result = $stmt->get_result();
  49. header("location: ../user-login.php");
  50. }
  51. }
  52. }
  53. }
  54. }else{
  55. header("location: ../user-signup.php");
  56. exit();
  57. }
  58.  
  59. $(document).ready(function() {
  60. $("#myForm").submit(function(event){
  61. event.preventDefault();
  62. var username = $("#signup-username").val();
  63. var pwd = $("#signup-pwd").val();
  64. var email = $("#signup-email").val();
  65. $(".signup-submit").text('Processing...');
  66. $.ajax({
  67. type: "POST",
  68. url: "includes/user-signup.php",
  69. data: "username="+ username + "&pwd="+ pwd + "&email="+ email,
  70. success: function(res) {
  71. if (res == "joined") {
  72. console.log(res);
  73. $(".signup-submit").text('Joined');
  74. $("input").val('');
  75. window.location.replace("user-login.php");
  76. } else if(res == "Email Match") {
  77. alert(data);
  78. $(".signup-email").val('');
  79. } else if (res == "failed to join") {
  80. console.log(res);
  81. $(".signup-submit").text('Sign Up');
  82. } else {
  83. // Stay Null
  84. }
  85. }
  86. });
  87. });
  88. });
  89.  
  90. $(document).ready(function() {
  91. $("#myForm").submit(function(event){
  92. event.preventDefault();
  93. var username = $("#signup-username").val();
  94. var pwd = $("#signup-pwd").val();
  95. var pwd = $("#signup-email").val();
  96. $(".form-message").load("includes/user-signup.inc.php",{
  97. username: username,
  98. pwd: pwd,
  99. email:email
  100. });
  101. });
  102. });
  103.  
  104. $("#signup-username, #signup-pwd, #signup-email").removeClass("input-error");
  105. var errorEmpty = "<?php echo $errorEmpty; ?>";
  106. var errorValid = "<?php echo $errorValid; ?>";
  107. if (errorEmpty == true $$ errorValid == true){
  108. $("#signup-username, #signup-pwd, #signup-email").addClass("input-error");
  109. if (errorEmpty == false && errorValid == false){
  110. $("#signup-username, #signup-pwd, #signup-email").val("");
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement