prepare($sql); $stmt->bind_param("i", $id_kasir); // Bind the id to the query $stmt->execute(); $result = $stmt->get_result(); // Check if the user exists if ($result->num_rows > 0) { $user = $result->fetch_assoc(); } else { echo "Pengguna tidak ditemukan."; exit; } } // Update user data if the form is submitted if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Get the form data $editUsername = $_POST['username']; $password = $_POST['password']; $phone = $_POST['phone']; $role = $_POST['role']; // Validate form fields (optional but recommended) if (!empty($editUsername) && !empty($phone) && !empty($role)) { // Check if password is provided if (!empty($password)) { // Hash the password $hashed_password = password_hash($password, PASSWORD_DEFAULT); // Update with new password $updateSql = "UPDATE kasir SET username = ?, password = ?, phone = ?, role = ? WHERE id_kasir = ?"; $updateStmt = $conn->prepare($updateSql); $updateStmt->bind_param("ssssi", $editUsername, $hashed_password, $phone, $role, $id_kasir); } else { // Update without changing password $updateSql = "UPDATE kasir SET username = ?, phone = ?, role = ? WHERE id_kasir = ?"; $updateStmt = $conn->prepare($updateSql); $updateStmt->bind_param("sssi", $editUsername, $phone, $role, $id_kasir); } $updateStmt->execute(); // Redirect to the users list after the update header("Location: index.php"); exit; } else { // Show error if any form field is empty echo ""; } } $conn->close(); ?>