title: Insert JSON in multiple array data to MySQL using PHP
body: <p>I want to insert my JSON data to MySQL DB using PHP...</p>
  
  <p>This is my JSON data called "data.json"</p>
  
  <pre><code>{
  "allRoundData": [{
      "name": "Animals",
      "timeLimitInSeconds": 20,
      "pointsAddedForCorrectAnswer": 10,
      "questions": [{
          "questionText": "Lions are carnivores: true or false?",
          "answers": [{
              "answerText": "True",
              "isCorrect": true
          }, {
              "answerText": "False",
              "isCorrect": false
          }]
      }, {
          "questionText": "What do frogs eat?",
          "answers": [{
              "answerText": "Pizza",
              "isCorrect": false
          }, {
              "answerText": "Flies",
              "isCorrect": true
          }]
      }, {
          "questionText": "Where do mice live?",
          "answers": [{
              "answerText": "In the sea",
              "isCorrect": false
          }, {
              "answerText": "On the moon",
              "isCorrect": false
          }, {
              "answerText": "On land",
              "isCorrect": true
          }, {
              "answerText": "In a tree",
              "isCorrect": false
          }]
      }]
  }]
  </code></pre>
  
  <p>}</p>
  
  <p>This is my PHP script</p>
  
  <pre><code>&lt;?php
  
  include 'bl_Common.php';
  
  $con = dbConnect();
  
   // use prepare statement for insert query
  $st = mysqli_prepare($con, 'INSERT INTO data (round_name, time_limit, points_added, question_text, answer_text, isCorrect) VALUES (?, ?, ?, ?, ?, ?)');
  
  // bind variables to insert query params
  mysqli_stmt_bind_param($st, 'siisss', $name, $time, $points, $question, $answer, $isCorrect);
  
  // read json file
  $filename = 'data.json';
  $json = file_get_contents($filename);   
  
  echo $json;
  
  //convert json object to php associative array
  $data = json_decode($json, true);
  
  // loop through the array
  foreach ($data as $row) {
  
      // get the employee details
      $name = $row["allRoundData"]["name"];
      $time = $row['allRoundData']['timeLimitInSeconds'];
      $points = $row['allRoundData']['pointsAddedForCorrectAnswer'];
      $question = $row['allRoundData']['questions']['questionText'];
      $answer = $row['allRoundData']['answers']['answerText'];
      $isCorrect = $row['allRoundData']['answers']['isCorrect'];
  
      // execute insert query
      mysqli_stmt_execute($st);
  }
  
  //close connection
  mysqli_close($con);
  </code></pre>
  
  <p>?></p>
  
  <p>I found an error that say "Notice: Undefined index: allRoundData in ..."
  But it's appearing there.</p>