<?
//include("confirmuser.php");
include("dbconnect.php");
$mode = 'NULL'; // while in 'test' mode it just echos the insert statements
// - set to NULL to exec queries
$record_delimiter = "\n";
$field_delimiter = "\t";
if(is_uploaded_file ($userfile)) {
// open uploaded file and read into a var
$filename = $HTTP_POST_FILES['userfile']['tmp_name'];
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
// Delete the contents located in the database
$del = mysql_query("DELETE from verizon where VerizonID <> '0'");
// now create array - each element being a row from the file
$contents_array = explode($record_delimiter, $contents);
reset ($contents_array);
while (list ($key, $val) = each ($contents_array)) {
$fields = explode($field_delimiter, $val);
// Get the commission amount if the number already exists
$result = mysql_query("SELECT Commission from verizon where PhoneNumber = $fields[1]");
// Insert records into database
$sql = "INSERT INTO verizon (PlanCode,PhoneNumber,CustName,Commission) VALUES('".trim($fields[0])."','".trim($fields[1])."','".trim($fields[2])."','".trim($fields[3])."')";
if ($result){
$row = mysql_fetch_array($result);
$commissionAmount = $row["Commission"] + $fields[3];
}
if ($mode=='test') {
echo $sql.'<br>';
}
else {
$res = @mysql_query($sql, $db)
or $sql_query = mysql_query("UPDATE verizon SET Commission='$commissionAmount' WHERE PhoneNumber='$fields[1]'")
or die ('<b>Insert failed.</b><br>MySQL error: '.mysql_error().'<br>Query: '.$sql);
}
}
print "<meta http-equiv=\"refresh\" content=\"0; URL=store.php\">";
}
else {
echo <<<FORM
<form action="$PHP_SELF" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
Upload: <input name="userfile" type="file"><br><br>
<input type="submit" value="Upload your verizon data file">
</form>
FORM;
}
?>
Thank you for the help!