I'm having trouble saving data to my firebase database.
Although I don't see any errors on the site, the data in firebase remains null and doesn't change no matter what I do.
Here is the code snippet. HTML
<html>
<head>
<title>Testing Site</title>
<script src="https://www.gstatic.com/firebasejs/10.8.0/firebase-app.js" type="module"></script>
<script src="https://www.gstatic.com/firebasejs/10.8.0/firebase-database.js" type="module"></scrip ${ strong2 } `,
]);
}
};
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-app.js";
import { getDatabase, ref, set } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-database.js";
const firebaseConfig = {
apiKey: "***************************",
authDomain: "***************************",
databaseURL: "***************************",
projectId: "***************************",
storageBucket: "***************************",
messagingSenderId: "***************************",
appId: "***************************"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getDatabase(app);
function ordernow(){
var floorNum = document.getElementById('floorNum').value;
var floorSize = document.getElementById('floorSize').value;
var lobbyNum = document.getElementById('lobbyNum').value;
var lobbySize = document.getElementById('lobbySize').value;
var windowsNum = document.getElementById('windowsNum').value;
var parkingLot = document.getElementById('parkingLot').value;
var parkingSize = document.getElementById('parkingSize').value;
var garbageRoom = document.getElementById('garbageRoom').value;
var garbageSize = document.getElementById('garbageSize').value;
var garden = document.getElementById('garden').value;
var gardenSize = document.getElementById('gardenSize').value;
var onceAWeek = document.getElementById('onceAWeek').checked;
var twiceAWeek = document.getElementById('twiceAWeek').checked;
var ThreeAWeek = document.getElementById('ThreeAWeek').checked;
var CleaningPerWeek = onceAWeek ? "lowonceAWeek" : (twiceAWeek ? "twiceAWeek" : (ThreeAWeek ? "ThreeAWeek" : "none"));
var city = document.getElementById('city').value;
var street = document.getElementById('street').value;
var buildingNum = document.getElementById('buildingNum').value;
var fName1 = document.getElementById('fName1').value;
var lName1 = document.getElementById('lName1').value;
var phone1 = document.getElementById('phone1').value;
var email1 = document.getElementById('email1').value;
var fName2 = document.getElementById('fName2').value;
var lName2 = document.getElementById('lName2').value;
var phone2 = document.getElementById('phone2').value;
var email2 = document.getElementById('email2').value;
set(ref(db, 'client/' + phone1), {
Contact1: {FirstName: fName1, LastName:lName1, PhoneNumber: phone1,email: email1},
Contact2: {FirstName: fName2, LastName:lName2, PhoneNumber: phone2,email: email2},
Address: {City: city, sStreet: street, BuildingNum: buildingNum},
BuildingData: {Floors: floorNum,FloorSize: floorSize,Lobbys: lobbyNum,Lobbysize: lobbySize,
Winows: windowsNum, ParkingLot: parkingLot, ParkingLotSize: parkingSize, GarbageRoom: garbageRoom,
GarbageRoomSize: garbageSize,Garden: garden,GardenSize: gardenSize},
CleaningPerWeek:CleaningPerWeek
})
.then(() => {
console.log('Data successfully written to Firebase');
})
.catch((error) => {
console.error('Error writing to Firebase: ', error);
});
}