-1

I have reference on this site to send data to MySQL but I don't know the function of this code $json = file_get_contents('php://input');

I have this jsonArray :

[{"id":"1","nilai":"1"},{"id":"2","nilai":"1"},{"id":"3","nilai":"1"},{"id":"4","nilai":"1"},{"id":"5","nilai":"1"}]

But again, I don't know how to send those json to database, and the tutorial in go*gle is so scrimpy for my issue. so I begging someone to help me.

Question :

  • Is it possible to add the jsonArray to database in case the String inside json is looped?

That's mean is it possible to add/insert those json to database? how to do? and the final maybe like this :

|----|-------|
| ID | Nilai |
|----|-------|
| 1  |   1   |
| 2  |   1   |
| 3  |   1   |
|... |  ...  |
|====|=======|
6
  • I've looking for a piece of code like json_decode(json) but i don't have an idea to create a php script for that, Commented Dec 14, 2016 at 8:26
  • take a look here will you an idea how to do it Commented Dec 14, 2016 at 8:30
  • @PavneetSingh and again with this code file_get_contents("php://input");, that's php://input is a special character or? Commented Dec 14, 2016 at 8:36
  • you can easily google these things and read about it , pretty easy to find Commented Dec 14, 2016 at 8:39
  • 1
    @PavneetSingh so it's just like uploading a file to server and read that file then execute the query? Commented Dec 14, 2016 at 8:43

1 Answer 1

0

Usually you do a HTTP POST with that JSON to a webserver, which will parse the data and it will insert to database ( MySQL). At the webserver will run a PHP code in most cases, but can be C#, Java. Usually you don't have access to MySql. Otherwise you have to build up a jdbc connection and use an SQL, not a JSON.

Here is an example hot to do a HTTP POST at Android.

Here and here you will find piece of PHP code.

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

2 Comments

can you explain with code how to do for the answer, or maybe you should comment for that suggest
thanks for the example sir, but i don't know about File_Get_Contents() and how to insert my json into a file like (xyz.json)

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.