I am uploading a file and it would either be a csv or tab delimited file. The code below basically loops through each record and inserts the record in the database. I want to have something that checks if the record exists and if it does then update the Commission field with the amount in the database plus the amount in the file. I have the phone number as a unique field,so it will fail when it tries to insert the same value. I know rather than failing I would use some update statement, but I just can't seem to get the syntax right. The code below isn't exactly what I have now, but it is very close. I'm sure it won't run the way it is now,but If you have any suggesstions I would greatly appreciate it.
Thanks,
Tony
while (list ($key, $val) = each ($contents_array)) {
$fields = explode($field_delimiter, $val);
$sql = "INSERT INTO $table(PlanCode,PhoneNumber,CustName,Commission) VALUES('".trim($fields[0])."','".trim($fields[1])."','".trim($fields[2])."','".trim($fields[3])."')";
if ($mode=='test') {
echo $sql.'<br>';
}
else {
$res = @($sql, $db)
or die ('<b>Insert failed.</b><br>MySQL error: '.mysql_error().'<br>Query: '.$sql);
}
}
}