How can i insert decoded json data using json string in php mysql database <p>I have this JSON string.</p> <pre><code>{"Challenges":[{"phoneNumber":"1234567809","name":"Test2 Test2"},{"phoneNumber":"1234567890","name":"Test1 Test1"},{"phoneNumber":"8733806964*","name":"Dennish Desouzs"}],"Message":[{"message":"testchallenge1"}],"Level":[{"level_name":"testchallenge1","level_design":"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022200000000000080002000000000000000002000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000200000000000000000002000000000000000000220000000000000000002000000000000000000020000060000000000000200000000000000000002000000000000000000000000000000000000000000000000000000","win_time":3,"play_no":1,"top_user_id":"45","no_challenge":0,"user_id":"45","win_no":1}]} </code></pre> <p>code is as below: <pre><code>mysql_select_db("hello") or die('Cannot select Database'); mysql_select_db("hello") or die('Cannot select Database'); $string=$_GET['records']; $arr=json_decode($string); $levelArray=array(); foreach ($arr['Level'] as $key=&gt;$value) { $levelArray[] = $arr-&gt;Level; print_r($levelArray); $j = 0 ; foreach($levelArray as $levelItem) { mysql_query("INSERT INTO level(user_id,level_name,no_challenge,level_design,play_no,win_no,win_time,top_user_id)VALUES('".$levelArray[$j]-&gt;user_id."','".$levelArray[$j]-&gt;level_name.'","'.$levelArray[$j]-&gt;no_challenge.'","'.$levelArray[$j]-&gt;level_design.'","'.$levelArray[$j]-&gt;play_no.'","'.$levelArray[$j]-&gt;win_no.'","'.$levelArray[$j]-&gt;win_time.'","'.$levelArray[$j]-&gt;top_user_id."'"); } } ?&gt; </code></pre> <p>Problem is that I cannot insert data in the database by getting the values and at first I have to get all the data from the above string and then level string have to insert level table and challenge record string array should be insert in challenge table so what I should do to get this above string output?</p>