data = await response.json();
                
                if (!response.ok || !data.success) {
                    throw new Error(data.error || 'Failed to save user data');
                }

                alert('Save data updated successfully!');
                window.location.reload();
            } catch (error) {
                console.error('Error saving user data:', error);
                alert('Failed to save user data: ' + error.message);
            }
        }

        function searchIn