nagasurendra commited on
Commit
ee59b14
·
verified ·
1 Parent(s): 4acfd4a

Update utils/database_handler.py

Browse files
Files changed (1) hide show
  1. utils/database_handler.py +11 -3
utils/database_handler.py CHANGED
@@ -32,11 +32,19 @@ def save_user(name, phone, email, password):
32
  print("Error: Email already exists.") # Debugging
33
  return False # Do not allow duplicate emails
34
 
 
 
 
35
  # Append the new user to the DataFrame
36
- new_user = {"Name": name, "Phone": phone, "Email": email, "Password": password}
37
  df = pd.concat([df, pd.DataFrame([new_user])], ignore_index=True)
38
 
 
 
 
39
  # Save the updated DataFrame back to the Excel file
40
- df.to_excel(CUSTOMERS_FILE, index=False)
41
- print("User saved successfully.") # Debugging
 
 
 
42
  return True
 
32
  print("Error: Email already exists.") # Debugging
33
  return False # Do not allow duplicate emails
34
 
35
+ # Ensure proper column structure
36
+ new_user = {"Name": name, "Phone": str(phone), "Email": email, "Password": password}
37
+
38
  # Append the new user to the DataFrame
 
39
  df = pd.concat([df, pd.DataFrame([new_user])], ignore_index=True)
40
 
41
+ # Ensure data types remain consistent
42
+ df["Phone"] = df["Phone"].astype(str) # Convert all phone numbers to strings
43
+
44
  # Save the updated DataFrame back to the Excel file
45
+ try:
46
+ df.to_excel(CUSTOMERS_FILE, index=False)
47
+ print("User saved successfully. Updated data:\n", df) # Debugging
48
+ except Exception as e:
49
+ print("Error while saving data to Excel:", e) # Debugging
50
  return True