Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. if (isset($_POST['submit'])){
  2. include_once 'dbh.inc.php';
  3.  
  4. $username = mysqli_real_escape_string($conn, $_POST['username']);
  5. $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
  6. $email = mysqli_real_escape_string($conn, $_POST['email']);
  7.  
  8. if(empty($username) || empty($pwd) || empty($email)){
  9. echo "Fill in all Fields!";
  10. }else {
  11. if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
  12. echo "Email is invalid!";
  13. }else{
  14. $stmt = $conn->prepare("SELECT * FROM users WHERE username=?");
  15. $stmt->bind_param("s", $uid);
  16. $uid = $username;
  17. $stmt->execute();
  18. $result = $stmt->get_result();
  19. $usernamecheck = mysqli_num_rows($result);
  20. $rowNum = $result->num_rows;
  21. if($rowNum > 0){
  22. echo "Username is taken!";
  23. }else{
  24. $stmt = $conn->prepare("SELECT * FROM users WHERE email=?");
  25. $stmt->bind_param("s", $uemail);
  26. $uemail = $email;
  27. $stmt->execute();
  28. $result = $stmt->get_result();
  29. $usernamecheck = mysqli_num_rows($result);
  30. $rowNum = $result->num_rows;
  31. if($rowNum > 0){
  32. echo "Email is taken";
  33. }else{
  34. $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
  35. $stmt = $conn->prepare("INSERT INTO users (username, pwd, email) VALUES (?, ?, ?)");
  36. $stmt->bind_param("sss",$uid, $password, $theemail);
  37. $uid = $username;
  38. $password = $hashedPwd;
  39. $theemail= $email;
  40. $stmt->execute();
  41. $result = $stmt->get_result();
  42. header("location: ../user-login.php");
  43. }
  44. }
  45. }
  46. }
  47. }else{
  48. header("location: ../user-signup.php");
  49. exit();
  50. }
  51.  
  52. include_once '../dbh.inc.php';
  53. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  54. $username = $_POST['username'];
  55. $email = $_POST['email'];
  56. $pwd = $_POST['pwd'];
  57. if(empty($username) || empty($pwd) || empty($email)){
  58. echo "Fill in all Fields!";
  59. exit();
  60. }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
  61. echo "Email is invalid!";
  62. exit();
  63. }else{
  64. $chk = "SELECT * FROM user WHERE email='$email'";
  65. $result = mysqli_query($conn, $chk);
  66. while ($row = mysqli_fetch_array($result)) {
  67. if ($row['email'] == $email) {
  68. echo "Email Match";
  69. exit();
  70. } else {
  71. $chk = "SELECT * FROM user WHERE username='$username'";
  72. $result = mysqli_query($conn, $chk);
  73. while ($row = mysqli_fetch_array($result)) {
  74. if ($row['username'] == $username) {
  75. echo "Username Match";
  76. exit();
  77. } else {
  78. $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
  79. $join = sprintf("INSERT INTO user(username, email, password) " .
  80. "VALUES ('%s', '%s', '%s', '%s'); ",
  81. mysqli_real_escape_string($conn, $username),
  82. mysqli_real_escape_string($conn, $email),
  83. mysqli_real_escape_string($conn, $hashedPwd),
  84. mysqli_insert_id($conn));
  85. if (mysqli_query($conn, $join)) {
  86. $i = "joined";
  87. } else {
  88. $i = "failed to join";
  89. }
  90. echo $i;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement