Hi all,
I have a text file with data in it separated line by line with RETURN ( \n ).
I need to populate a mysql database with the records in this text file. My approach is as follows:
I used fopen() to open, and fread to read the contents of the file.
I then explode() the contents using \n as delimiter.
Finally I throw the array from explode() into a FOR loop, for insertion into my database.
For some strange reason, only the first element of the array gets posted, before the script quits. No errors, just a single post, and that's it.
Below is my code.
Any help will be appreciated.
<?php
$filename = "mytextfile.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
$records = explode("\n",$contents);
include ("connectionInfo.php");
$db = "mydatabase";
for($i=0; $i<sizeof($records); $i++)
{
$query = "insert into mytable (summary) ";
$query .= "values ('$records[$i]')";
$result = mysql_db_query($db,$query,$connection);
}
mysql_close($connection);
fclose ($fd);
?>