This is what my php code looks like. I am using a form to upload a file and i use isset to check to see if i hit the upload button which then checks to ensure i have a $FILES then i take the $fileName and parse the file into the dba table fields however I have come to realise that i might not be getting the file from the form and parsing it do you have any suggestions on if i am doing this correctly with the $FILES['userfile']['name']
<?php
if(isset($POST['upload']) && $FILES['userfile']['size'] > 0)
{
$fileName = $FILES['userfile']['name'];
$tmpName = $FILES['userfile']['tmp_name'];
for($i=0; $i<sizeof($fileName); $i++)
{
$line = trim($fileName[$i]);
$arr = explode("\t", $line);
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ','
$query = "INSERT INTO 2004Scores (Bib, FirstName, LastName, Addr, City, State, Zip, Email, TimeOfDay) ".
"VALUES ('". implode("','", $arr) ."')";
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
# first get a mysql connection as per the FAQ
$hostname_mydba = "localhost";
$database_mydba = "ResultsDB";
$username_mydba = "root";
$password_mydba = "pass";
$mydba = mysql_connect($hostname_mydba, $username_mydba, $password_mydba) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_mydba);
mysql_query($query) or die(mysql_error());
}
fclose($fp);
echo "<br>File $fileName uploaded<br>";
}
?>