Hey guys, I’m building a database web with reactjs,expressjs and MySQL.
My backend handling UPDATE query is like this
I have two tables Users
. I now can only update all attributes at a time. But I wonder how I can only update table attributes that users input into the frontend form? Like I only changed their Username, then I only update Username and keep everything else the same.
If you use the same names on the front end (pageid, page_description and profile_picture), you might be able to simplify it. Something like this?
//remove the properties that are not needed
let formdata_2 = [req.body, req.body.username];
Presumably if you’ve got a form that updates a users data, there are going to be values in the form already (existing user information) , so it’s more than likely the same data (apart from password and maybe a couple of other fields) will be re-submitted in any case. If you are not pre-filling data, you can filter out the request body properties that have empty values and still do it the same way, but then how would a user send an empty value for, say, description if they want it empty?