title: PHP split a string and insert in MySQL
body: <p>I am using AJAX to send an array of values to a PHP page that will insert the data into MySQL database. The problem is that I am not sure how to split the data into 5 different veriables and loop to insert into DB.</p>
  
  <p>AJAX Request:
  Array:</p>
  
  <pre><code>[".testimonial", 1119, 316, 1663, 608, "#header", 723, 66, 1663, 608]
  </code></pre>
  
  <p>Posting the array:</p>
  
  <p>Sending Array Parameters using " ; " to split.</p>
  
  <pre><code>clicks  
  .testimonial;1119;316;1663;608;#header;723;66;1663;608
  </code></pre>
  
  <p>Source Sent:</p>
  
  <pre><code>clicks=.testimonial%3B1119%3B316%3B1663%3B608%3B%23header%3B723%3B66%3B1663%3B608
  </code></pre>
  
  <p>PHP Page</p>
  
  <pre><code>&lt;?php
  
  $clicks = $_GET["clicks"];
  $clickArray = explode(";",$clicks);
  $arrays = array_chunk($clickArray, 5);
  
  foreach ($arrays as $array_num =&gt; $array) {
    foreach ($array as $item_num =&gt; $item) {
      echo "". $item . "&lt;br/&gt;";
    }
  }
  
  
  $servername = "localhost";
  $username = "root";
  $password = "password";
  $dbname = "clickmap";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  }
  
  
  $sql = "INSERT INTO data (user_id, identifier_name, pos_x, pos_y, window_width, window_height, status)
  VALUES ('1', '$postIdentifier', '$postPos_x', '$postPos_y','$postWindowWidth','$postWindowHeight', 'ok')";
  
  
  if ($conn-&gt;query($sql) === TRUE) {
      echo "New record created successfully";
  } else {
      echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;
  }
  
  $conn-&gt;close();
  
  ?&gt;
  </code></pre>
  
  <p>Current PHP Result:</p>
  
  <pre><code>.testimonial
  1119
  316
  1663
  608
  #header
  723
  66
  1663
  608
  New record created successfully
  </code></pre>