Send data to mysql database

Tags: ,



I am trying to replace the data in a MySQL row. I have the code for the user to sign up, and when they sign up they are assigned an id and their “plannerTable” is set to null. I know how to receive the data from the users row, but how do I replace the data in the users “plannerTable”? -Josh If more info is needed I am happy to supply more info.

Code:

var clearQuestion = document.getElementById("clearPopup")

document.onkeydown = function(e) {
        if (e.which == 27 && clearQuestion.style.display != 'none') {
                clearQuestion.style.display = 'none';
        }
}
if (localStorage.plannerTable === undefined) {
        saveEdits()
}

if (typeof localStorage.plannerTable != 'object' && localStorage.plannerTable !== undefined) {
    var parsedPlannerTable = JSON.parse(localStorage.plannerTable)
} else {
    parsedPlannerTable = localStorage.plannerTable
}

function checkEdits() {
    if (localStorage.plannerTable !== undefined && localStorage.plannerTable !== null) {
        let plannerTableDict = parsedPlannerTable
        for (id in plannerTableDict) {
             if (plannerTableDict[id] !== null && plannerTableDict[id] !== '') {
                 document.getElementById(id).innerHTML = plannerTableDict[id]
             }
        }
    }
}

function saveEdits() {
    let tempPlannerDict = {}
    for (r=1; r<10; r++) {
        for (c=1; c<8; c++) {
            try {
                tempPlannerDict['iR' + r + 'C' + c] = document.getElementById('iR' + r + 'C' + c).innerHTML
            } catch (error) {
            }
        }
    }
    localStorage.plannerTable = JSON.stringify(tempPlannerDict)
}

function clearPlanner(){
    localStorage.removeItem('plannerTable')
    location.reload()
}

function clearWork(){
    let tempPlannerDict = parsedPlannerTable
    let emptyAmount = 0
    for (element in tempPlannerDict) {
        // console.log(element.substring(2,3), element.substring(4), element)
        if (element.substring(2,3) != 1 && element.substring(4) != 1) {
            // console.log('clearing item')
            tempPlannerDict[element] = ''
                        emptyAmount++
        }
    }
    console.log(emptyAmount, tempPlannerDict)
    if (emptyAmount == 57) {
        localStorage.removeItem('plannerTable')
    } else {
        localStorage.plannerTable = JSON.stringify(tempPlannerDict)
    }
}

Answer

I am assuming that the user id is the table key, meaning that all users have a unique id.

To change the plannerTable you need to execute a query that resembles this:

UPDATE usersTable SET plannerTable = ? WHERE id = ? and pass two items to this query – plannerTable content (whatever it is in your app) and the user id for the user that you want to change.



Source: stackoverflow