I'm using the code specified below to import a txt file into mysql via php and fopen. It imports all the rows of data from my txt file as intended, however no matter what the txt file contains my script always adds one extra unintended row with a blank field for column data 2. I checked the txt file and there is no spaces or whitespace at the very end.
mysql_connect("$dbhost", "$dbuser", "$dbpasswd") or die(mysql_error());
mysql_select_db("$dbname") or die(mysql_error());
$f = fopen("import.txt", "r");
while(!feof($f))
{
$data = explode(" ", fgets($f));
$data1 = 'foobar';
$inputkey = $data[0];
mysql_query("INSERT INTO `reviewdata` (data1, data2)
VALUES ('$data1', '$inputkey')") or die(mysql_error());
}
fclose($f);