firebase / firebase/codelab-friendlychat-web

Am getting the error of firebase.database is not a function when tryna use update syntax using javascript. here are my 2 files

Open
#674 0 comments 0 reactions 0 assignees View on GitHub
codelab
Dominant language
JavaScript
Stars
1.9k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description




Retrieve







.labs{
display: inline-block;
width: 100px;
}

NFC MTC GRAB CUSTOMERS


MTC GRAB







name
username
email
password

SEARCH


Back
                                     
Add User
   
Add driver
Driver's list


Sno
Full Name
Username
email
password
Control Center








function AddItemToTable(fullname,username,email,password) {
var tbody = document.getElementById("tbody1");
let tr = document.createElement("tr");
let td0 = document.createElement("td");
let td1 = document.createElement("td");
let td2 = document.createElement("td");
let td3 = document.createElement("td");
let td4 = document.createElement("td");
stdList.push([fullname,username,email,password]);
td0.innerHTML = ++stdNo;
td1.innerHTML = fullname;
td2.innerHTML = username;
td3.innerHTML = email;
td4.innerHTML = password;
td1 .classList +="nameField";
td2.classList +="dateField";
td3.classList +="timeField";
td4.classList +="phoneField";
tr.appendChild(td0);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tr.appendChild(td4);
var ControlDiv = document.createElement("div");
ControlDiv.innerHTML = '<button type="button" class="btn btn-info" my-2 ml-2" data-toggle="modal" data-target="#exampleModalCenter" onclick = "FillTboxes('+stdNo+')"> Edit </button>';
ControlDiv.innerHTML += '<button type="button" class="btn btn-info" my-2 ml-2" data-toggle="modal" data-target="#exampleModalCenter" onclick = "FillTboxes(null)"> Add </button>';


tr.appendChild(ControlDiv);
tbody.appendChild(tr);
}

function AddAllItemsToTable(TheStudent) {
stdNo = 0;
tbody.innerHTML = "";
TheStudent.forEach(element => {
AddItemToTable(element.fullname, element.username, element.email,element.password );
});
}


//............................................gettign data........................//
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.3/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.8.3/firebase-analytics.js";

const firebaseConfig = {
apiKey: #######
authDomain: #############
databaseURL: ############
projectId: #########
storageBucket: ###########
messagingSenderId: #########
appId: ########
measurementId: #########
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);

var stdNo;
import {getDatabase, ref , child, onValue, get}
from "https://www.gstatic.com/firebasejs/9.8.3/firebase-database.js";

const db = getDatabase();


function GetAllDataOnce(){
document.getElementById("tbody1").innerHTML="";
stdNo = 0;
const dbref = ref(db);

get(child(dbref, "UsersList"))
.then((snapshot)=>{

var students =[];
snapshot.forEach(childSnapshot =>{
students.push(childSnapshot.val());
});

AddAllItemsToTable(students);
});
}

window.onload = GetAllDataOnce;

var searchBar = document.getElementById("SearchBar");
var searchBtn = document.getElementById("SearchBtn");
var category = document.getElementById("CategorySelected");
var tbody = document.getElementById("tbody1");

function SearchTable(Category){

var filter = searchBar.value.toUpperCase();
var tr = tbody.getElementsByTagName("tr");
var found;

for (let i = 0; i < tr.length; i++) {
var td = tr[i].getElementsByClassName(Category);

for ( let j = 0; j < td.length; j++) {
if(td[j].innerHTML.toUpperCase().indexOf(filter) > -1){
found=true;
}

}

if(found){
tr[i].style.display="";
found=false;

}
else{
tr[i].style.display="none";
}
}

}

searchBtn.onclick = function(){
if(searchBar.value==""){
SearchTable("nameField");
}

else if(category.value==1)
SearchTable("nameField");

else if(category.value==2)
SearchTable("dateField");

else if(category.value==3)
SearchTable("timeField");

else if(category.value==4)
SearchTable("phoneField");
};







var firebase= {
apiKey: ########
authDomain: ###########
databaseURL: #############
projectId: ########
storageBucket: ##########
messagingSenderId:#########
appId: ############
measurementId: ###########
};

var stdNo = 0;
var stdList =[];
var ModName = document.getElementById('NameMod');
var ModRoll = document.getElementById('RollMod');
var ModSec = document.getElementById('SecMod');
var ModPass = document.getElementById('PassMod');

var BTNmodAdd = document.getElementById('AddModBtn');
var BTNmodUpd = document.getElementById('UpdModBtn');
var BTNmodDel = document.getElementById('DelModBtn');
function FillTboxes (index){
if(index==null){
ModName.value = "";
ModRoll.value = "";
ModSec.value = "";
ModPass.value = "";
BTNmodAdd.style.display='inline-block';
BTNmodUpd.style.display='none';
BTNmodDel.style.display='none';
}else{
--index;
ModName.value = stdList[index][0];
ModRoll.value = stdList[index][1];
ModSec.value = stdList[index][2];
ModPass.value = stdList[index][3];
ModPass.disabled = true;
BTNmodAdd.style.display='none';
BTNmodUpd.style.display='inline-block';
BTNmodDel.style.display='inline-block';

}
}
function Updstd(){
firebase.database().ref('UsersList/'+ModRoll.value).update(
{
fullname: ModName.value,
username: ModRoll.value,
email : ModSec.value,
password : ModPass.value
},
(error) =>{
if(error){
alert("failed to update the records");
}else{
alert("success updated");
GetAllDataOnce();
$("exampleModalCenter").modal('hide');

}
}
)
}

function Delstd(){
firebase.database().ref('UsersList/'+ModRoll.value).remove()

alert("deleted successfully");
GetAllDataOnce();
$("exampleModalCenter").modal('hide');


};

Contributor guide

Open the contributing guide

Research direction

Start by reading the inline module script in the supplied HTML and js2.js, then reproduce the firebase.database error with the shown update flow. Compare the Firebase imports and initialization with the update entry point; done means the UsersList record updates without the reported TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.