title: Read a text file and transfer contents to mysql database
body: <p>I need a php script to read a .txt file.</p>
  <p>The content of the text file are like this:</p>
  <p><strong>data.txt</strong></p>
  <pre><code>145|Joe Blogs|17/03/1954
  986|Jim Smith|12/01/1976
  234|Paul Jones|19/07/1923
  098|James Smith|12/09/1998
  234|Carl Jones|01/01/1925
  </code></pre>
  <p>These would then get stored into a database like this</p>
  <p>**DataID |Name      |DOB **</p>
  <pre><code>234    |Carl Jones|01/01/1925
  </code></pre>
  <p>I would be so grateful if someone could give me script to achieve this.</p>
  <h3>Update:</h3>
  <pre><code>&lt;?
  $handle = @fopen(&quot;data.txt&quot;, &quot;r&quot;);
  $conn = mysql_connect(&quot;localhost&quot;,&quot;username&quot;,&quot;password&quot;); 
  mysql_select_db(&quot;mydatabase&quot;,$conn);
  while (!feof($handle)) // Loop til end of file.
  {
  $buffer = fgets($handle, 4096);
   // Read a line.
  list($a,$b,$c)=explode(&quot;|&quot;,$buffer);
  //Separate string by the means of |
  echo $a.&quot;-&quot;.$b.&quot;-&quot;.$c.&quot;&lt;br&gt;&quot;;
  $sql = &quot;INSERT INTO data_table (iddata, name, age) VALUES('&quot;.$a.&quot;','&quot;.$b.&quot;',&quot;.$c.&quot;)&quot;;   
  mysql_query($sql,$conn) or die(mysql_error());
  }
  ?&gt;
  </code></pre>
  <p>get the following error error in your SQL syntax; ...for the right syntax to use near ')' at line 1</p>