-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   |
|... |  ...  |
|====|=======|
dondo
  • 99
  • 12
  • 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, – dondo Dec 14 '16 at 08:26
  • [take a look here](http://stackoverflow.com/questions/16684188/php-inserting-json-data-into-mysql-database-from-android) will you an idea how to do it – Pavneet_Singh Dec 14 '16 at 08:30
  • @PavneetSingh and again with this code `file_get_contents("php://input");`, that's `php://input` is a special character or? – dondo Dec 14 '16 at 08:36
  • you can easily google these things and read about it , pretty easy to find – Pavneet_Singh Dec 14 '16 at 08:39
  • 1
    @PavneetSingh so it's just like uploading a file to server and read that file then execute the query? – dondo Dec 14 '16 at 08:43
  • i already answered this question i invite you too see this link http://stackoverflow.com/questions/41107092/tutorial-to-send-data-as-jsonarray-to-mysql-in-android-using-php/43932884#43932884 – Ràbàh Blàck May 12 '17 at 08:28

1 Answers1

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.

Community
  • 1
  • 1
matheszabi
  • 594
  • 5
  • 16
  • can you explain with code how to do for the _answer_, or maybe you should comment for that suggest – dondo Dec 14 '16 at 08:28
  • 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) – dondo Dec 14 '16 at 08:40