title: PHP: Get each POST data from a text file and insert it to database
body: <p>I have a hard time on how to get the POST data from the text file. I have this line of text from my text file:</p>
  
  <blockquote>
    <p>Wednesday October 11, 2017, 04:53 AM,reader_name=%22Impinj%20RFID%20Reader%22&amp;mac_address=%2200%3a16%3a25%3a10%3a7E%3a85%22&amp;line_ending=%0a&amp;field_delim=%2c&amp;field_names=antenna%5fport%2cepc%2cpeak%5frssi%2ctid&amp;field_values=1%2c%22503030393839343834323200%22%2c%2d50%2c%22E280110520005756DE620231%22%0a1%2c%22000000000000001000000441%22%2c%2d53%2c%22E28011602000728E91750917%22%0a1%2c%2288000008%22%2c%2d60%2c%22E280116020007224B7650909%22%0a1%2c%22000000000000001000000441%22%2c%2d54%2c%22E28011602000728E91750917%22%0a1%2c%22503030393839343834323200%22%2c%2d48%2c%22E280110520005756DE620231%22%0a</p>
  </blockquote>
  
  <p>the POST data are the following:
  <strong>reader_name, mac_address, line_ending, field_delim, field_names, and field_values</strong></p>
  
  <p>I have created a code that will read a data from the text file but it failed:</p>
  
  <pre><code>&lt;?php
  $fn = "log.txt";
  $read = readfile($fn);
  
  
  // Store the POST variables.
  $readerName = $_POST['reader_name'];
  $macAddress = $_POST['mac_address'];
  $lineEnding = $_POST['line_ending'];
  $fieldDelim = $_POST['field_delim'];
  $fieldNames = $_POST['field_names'];
  $fieldValues = $_POST['field_values'];
  
  //Connect to the database.
  $con = mysqli_connect('localhost', 'root', '153624123', 'test') or die("Unable to select database");
  
  // Replace the field delimiter with a comma.
  str_replace($fieldDelim, ",", $fieldNames);
  
  // Break the field values up into rows.
  $rows = explode("\n", $fieldValues);
  
  // Remove the last row. It's always blank
  if (sizeof($rows))
      array_pop($rows);
  
  $fieldNames = "reader_name,mac_address," . $fieldNames;
  
  foreach ($rows as $row) {
      $row = $readerName . "," . $macAddress . "," .
              $row;
      $query = mysqli_query($con, "INSERT INTO tags ($fieldNames) VALUES ($row)");
      echo "INSERT INTO tags ($fieldNames) VALUES ($row)" . '&lt;br /&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p>I tried searching other ways in google but found no luck. the text file is from the RFID that we bought for our project which is called "speedway connect" product. it has a website and they posted their source code for HTTP POST. i followed everything but i got no luck.</p>
  
  <p><a href="https://support.impinj.com/hc/en-us/articles/202756148-HTTP-POST-with-Speedway-Connect-software-VIDEO-" rel="nofollow noreferrer">https://support.impinj.com/hc/en-us/articles/202756148-HTTP-POST-with-Speedway-Connect-software-VIDEO-</a></p>