13) { $showUsernameModal = true; $modalMessage = "Nomor telepon harus terdiri dari 11 hingga 13 angka."; } // Check if passwords match else if ($password !== $confirmPassword) { $showUsernameModal = true; $modalMessage = "Password tidak sama."; } else { // Check if username already exists $checkUsername = "SELECT username FROM kasir WHERE username = ?"; $checkStmt = $conn->prepare($checkUsername); $checkStmt->bind_param("s", $newUsername); $checkStmt->execute(); $result = $checkStmt->get_result(); if ($result->num_rows > 0) { // Set flag to show modal $showUsernameModal = true; $modalMessage = "Username sudah digunakan. Silakan pilih username lain."; } else { // Hash the password $hashed_password = password_hash($password, PASSWORD_DEFAULT); // Insert the user information into the database $insertSql = "INSERT INTO kasir (username, password, phone, role) VALUES (?, ?, ?, ?)"; $insertStmt = $conn->prepare($insertSql); $insertStmt->bind_param("ssss", $newUsername, $hashed_password, $phone, $role); $insertStmt->execute(); // Redirect to the users list after the insert header("Location: index.php"); exit; } } } else { // Show error if any form field is empty $showUsernameModal = true; $modalMessage = "Harap isi semua kolom."; } } // Variable for modal display $showUsernameModal = isset($showUsernameModal) ? $showUsernameModal : false; $modalMessage = isset($modalMessage) ? $modalMessage : ""; $conn->close(); ?>