#Hi! I want to know how to return a result in my desired format.
53 messages · Page 1 of 1 (latest)
I don't know where to start with this one, are two tables being used in this one the first table is customers and the second is address where the customers address and the rest of the info is being stored. they are linked by an address id
I want to do a post request
whats your question?
Hmm, the entire thing is an object, and .address is also an object so .address is an object in an object
ooh thankyou
hm i just dont know how to start coding this thing. So basically do i write an sql statement to insert all of these values into the database first and then worry about the result?
;~;
What values? And the result you want is that JSON object?
well basically i have two tables , the first table containing customer information like the store ID , name ,email and second table with adress information which is all of the information inside the adress array? and then i am basically using Postman to test for request and if the response is correct.
Yes and after it runs I return the result as the JSON object?
i am so sorry i am still not too familiar with backend dev so its hard for me to describe what i am doing
(I unfortunately can't help; I don't know SQL)
ooh that's ok , the object in object comment helped me know what to even start googling for
thanks a lot
do you just want to fill in the object with the information you have?
and the data you have are the "tables" are those html tables?
Yes , I want to use postman to send a request body with the info to insert into the sql database i have running in workbench , and then show the updated info in the format that is in the picture
?
not sure what postman is, but are you trying to send the data from the tables in your frontend to your backend, put the data into your desired format, then into your database?
yes
at whatever point you want to submit the data inputted, on a frontend js page, you can get all the data from that table, put it into an object, and instead of using postman you can make a fetch to your backend.
const obj = {} // this is your table cell data in the proper format
fetch("/route", { // put whatever route youre posting to
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(obj)
})
in your backend im not sure if youre using express or anything
but you want to receive that post request, get the data from the fetch body, then upload that data into your database (im not sure how to use SQL)
oooh
thankyou for the help!
i am still new to back-end web dev
so im not that good with the terms
thanks again @sterile comet!
your welcome, are you using express for backend?
its a nice package its very helpful
hmm
i have heard a lot about php/express
but i honestly don't know what im using
im just doing what my lecturer told me
what does your backend code look like
well so there are multiple parts
i use vs code to do all of it
the first is creating a js file that connects to the database
it looks like this
and then a js file for ???
looks like this?
i think im using express
yes you are using express
O no
says it at the top
idk what im doing
require("express")
dont want to get to off topic but if you still have questions you can ask otherwise you can close the thread