I'm currently working on a php upload script where the user uploads a text file exported from excel. They input multiple products into it and then upload the txt file to the server when they're done. I have it TRUNCATE the table everytime so the DB is emptied when the file is upload. That way the file and the website run inline with each other. No onto my problem. For some reason it's only taking the first line thats inside the text file and not taking the other rows. I don't know if I made an error and for some reason it's not looping through to get the 2nd row and so on but if someone could please look at my code and let me know what's wrong with it that'd be great. Thanks in advance!
<?
break;
case "force_import":
$hmm = $_REQUEST['upfile'];
$uploaddir = '/home/xxxx/www/nhr/cms/upload/';
$uploadfile = $uploaddir . basename($_FILES['upfile']['name']);
if (move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile)) {
$upstatus = "File was successfully uploaded.";
} else {
$upstatus = "File was not uploaded. Please try again.";
}
// Include config file
include('common.php');
$link = dbConnect();
$query = "TRUNCATE TABLE training";
$result = mysql_query($query);
if (!$result) {
fail ("Error querying database");
}
// Fetch the current time
$posted = time();
$lines = file ($uploadfile);
foreach ($lines as $line_num => $line)
{
$pieces = explode("|", $line);
$query = "INSERT INTO training (title, lprice, wprice, image, features, audio, oview, compat, posted)
VALUES('$pieces[0]', '$pieces[1]', '$pieces[2]', '$pieces[3]', '$pieces[4]', '$pieces[5]', '$pieces[6]', '$pieces[7]', $posted)";
// Execute Query
$result = @mysql_query($query) or die ("Error: $query" . mysql_error());
}
?>