I need a php script to read a .txt file.
The content of the text file are like this:
data.txt
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
These would then get stored into a database like this
*DataID |Name |DOB *
234 |Carl Jones|01/01/1925
I would be so grateful if someone could give me script to achieve this.
Update:
<?
$handle = @fopen("data.txt", "r");
$conn = mysql_connect("localhost","username","password");
mysql_select_db("mydatabase",$conn);
while (!feof($handle)) // Loop til end of file.
{
$buffer = fgets($handle, 4096);
// Read a line.
list($a,$b,$c)=explode("|",$buffer);
//Separate string by the means of |
echo $a."-".$b."-".$c."<br>";
$sql = "INSERT INTO data_table (iddata, name, age) VALUES('".$a."','".$b."',".$c.")";
mysql_query($sql,$conn) or die(mysql_error());
}
?>
get the following error error in your SQL syntax; ...for the right syntax to use near ')' at line 1