Advertisement
rex9840

Redirection copy paster

Jan 11th, 2024
1,166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. @include 'connect.php';
  2.  
  3. $errors = [];
  4.  
  5. if (isset($_POST['submit'])) {
  6.     $username = $_POST['username'];
  7.     $email = $_POST['email'];
  8.     $password = $_POST['pwd'];
  9.     $hashedPassword = password_hash($password, PASSWORD_DEFAULT);
  10.  
  11.     // Validate other fields if needed
  12.  
  13.     // Check if user already exists
  14.     $select = "SELECT * FROM login_data WHERE username = '$username'";
  15.     $result = mysqli_query($conn, $select);
  16.  
  17.     if (mysqli_num_rows($result) > 0) {
  18.         $errors[] = 'User already exists!';
  19.     } else {
  20.         // Insert user data into the database with hashed password
  21.         $insert = "INSERT INTO login_data (username, email, password) VALUES ('$username', '$email', '$hashedPassword')";
  22.         mysqli_query($conn, $insert);
  23.         header('location: login.php'); // Redirect to login page after successful registration
  24.         exit();
  25.     }
  26. }
  27. ?>
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement