Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. <?php
  2. include("include/dbconnect.php");
  3. session_start();
  4. if (isset($_POST["username"]) && isset($_POST["email"]) && isset($_POST["password"]) && isset($_POST["confirmpass"])) {
  5. $username = $conn->escape_string($_POST["username"]);
  6. $password = $conn->escape_string(password_hash($_POST["password"], PASSWORD_DEFAULT));
  7. $confirmpass = $conn->escape_string(password_hash($_POST["confirmpass"], PASSWORD_DEFAULT));
  8. $email = $conn->escape_string($_POST["email"]);
  9. $ip = $_SERVER["REMOTE_ADDR"];
  10. if ($_POST["password"] != $_POST["confirmpass"]) {
  11. $error = "Confirm password is not equal to the password";
  12. }else {
  13.  
  14. $sql = "SELECT * FROM users WHERE email='$email'";
  15. $result = $conn->query($sql);
  16. if ($result->num_rows > 0) {
  17. $error = "Email already exists";
  18. }else{
  19.  
  20. $sql1 = "SELECT * FROM users WHERE username='$username'";
  21. $result1 = $conn->query($sql1);
  22. if ($result1->num_rows > 0) {
  23. $error = "Username already registered.";
  24. }
  25. else {
  26. $sql2 = "INSERT INTO users (username, email, password, confirmpassword, ip)
  27. VALUES ('$username', '$email', '$password', '$confirmpass', '$ip')";
  28. if ($conn->query($sql2)) {
  29. header("Location: login.php");
  30.  
  31. }
  32. else {
  33. $error = mysqli_error($conn);
  34. }
  35. }
  36. }
  37. }
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement