php - How to store multiple parameters passed as POST in database -


i have passed json encoded parameters post have captured , decoded in php file. have used following code that.

$entitybody = file_get_contents('php://input'); $entitybody = json_decode($entitybody, true); 

i have passed json encoded parameters follows:

{  "id": "5",  "name": "abcd",  "imei": "1234" } 

actually number of parameters passing post may 15 20 going insert in table i.e. each of them field in table in mysql database. new json , php. method know value of each parameter after checking whether set following:

if(isset($entitybody['id']))    ... elseif(isset(...))    ... 

it clear there many if , else when there many parameters. there way can store parameters in table in more efficient way. if helps me in doing grateful.

use json_decode function parse json array or object.

$a = json_decode($entitybody); $a->id; 

refer http://php.net/manual/en/function.json-decode.php


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -