Reputation: 65
I am trying to insert query into SQL Server using window authentication with nodejs. I have done with get request of select query. but now am trying the post request with insert query. But I can't pass my req.body.address into the following query. the address data have json value.
here my request data,
Upvotes: 0
Views: 5017
Reputation: 550
You need to save as string in user_address field.
eg: If you want to save as address like this:
user_address: `${req.body.address.street},${req.body.address.district},${req.body.address.city}`
Or
user_address: JSON.stringify(req.body.address)
whenever you want to show the address you need to do JSON.parse(user_address).
In nutshell, value must be a single value.
Upvotes: 1
Reputation: 6762
Your mysql
library is probably, by default, applying a standard string conversion to req.body.address
. When you do this to a javascript object you obtain [object Object]
:
req.body.address.toString() // "[object Object]"
Objects needs to be converted to string using JSON.stringify()
:
"user_address": JSON.stringify(req.body.address)
Upvotes: 1