0

I have the following JSON values:

[newcomposeMail={"msg":"test mail","senderUserId":"1006","subject":"test","to":"10002"}, composeMail]

My query is:

 INSERT INTO `push_msg_table`(`pid`, `subject`, `msg`, `sentuserid`, `sent_time`, `upload_path`, `status`) VALUES()

I need to insert these values to the mysql table. I am new to JSON.

2

3 Answers 3

0

Try to use in php

json_decode(newComposeemail,true);

Adding true you will get proper Array else it will return Object in php

If there are multiple entries in json , then you will have to loop through the json array, in order to insert multiple entries in DB

Sign up to request clarification or add additional context in comments.

Comments

0

Make sure firstly that you are getting all json values in php by request array or json_decode function.

Then after you get all the values which will come in the form of strings, so the string values which are integer should be converted into integer only then the INSERT query will work. So the query will be like this.

INSERT INTO push_msg_table(pid, subject, msg, sentuserid, sent_time, upload_path, status) VALUES(integer,string,string,integer,string,string,integer);

Hope this helps to you !!

Comments

0

try below code:

$newcomposeMail= '{"msg":"test mail","senderUserId":"1006","subject":"test","to":"10002"}';

$qryVal = json_decode($newcomposeMail,true);

//echo $qryVal->{'subject'};//here how you get json values

$qry ="INSERT INTO `push_msg_table`(`pid`, `subject`, `msg`, `sentuserid`, `sent_time`, `upload_path`, `status`) VALUES($pid,'".$qryVal->{'subject'}."','".$qryVal->{'msg'}."','".$qryVal->{'senderUserId'}."',.............";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.