query($checkEmail); if ($result->num_rows > 0) { // Store the error message in the session $_SESSION['error'] = "Email already exists. Please use a different email."; header('Location: ../register.php'); // Redirect to the register page exit(); } else { // Hash the password before storing it $hashedPassword = password_hash($password, PASSWORD_BCRYPT); // Insert the user data with hashed password $sql = "INSERT INTO user (`user_name`, `user_email`, `user_pass`, `user_type`, `user_otp`) VALUES ('$uName', '$email', '$hashedPassword', '$uType', NULL)"; if ($conn->query($sql) === TRUE) { // Get the user ID of the newly registered user $userId = $conn->insert_id; // Optionally, send an email or OTP for verification here // Redirect to login page after successful registration header('Location: ../login.php'); exit(); } else { $_SESSION['error'] = "Error: " . $sql . "
" . $conn->error; header('Location: ../register.php'); exit(); } } } $conn->close(); ?>