Skip to main content

Show Posts

This section allows you to view all Show Posts made by this member. Note that you can only see Show Posts made in areas you currently have access to.

Messages - Thia B

1
Questions / update existing records in a table using an excel csv import file.
I want to update existing records in a table using an excel csv import file.

the table name is aflossingen and has the columns: AflossingID, VoorschotID, Aflossingdatum, Aflossingsbedrag, Afgelost, Saldo.

This is the code PHPRad has generated, which can only do an INSERT:
Code: [Select]
function import_data(){
if(!empty($_FILES['file'])){
$finfo = pathinfo($_FILES['file']['name']);
$ext = strtolower($finfo['extension']);
if(!in_array($ext , array('csv'))){
$this->set_flash_msg("Document formaat niet ondersteund", "danger");
}
else{
$file_path = $_FILES['file']['tmp_name'];
if(!empty($file_path)){
$request = $this->request;
$db = $this->GetModel();
$tablename = $this->tablename;
$options = array('table' => $tablename, 'fields' => '', 'delimiter' => ',', 'quote' => '"');
$data = $db->loadCsvData( $file_path , $options , false );
if($db->getLastError()){
$this->set_flash_msg($db->getLastError(), "danger");
}
else{
$this->set_flash_msg("Data imported successfully", "success");
}
}
else{
$this->set_flash_msg("Error uploading file", "danger");
}
}
}
else{
$this->set_flash_msg("No file selected for upload", "warning");
}
$this->redirect("aflossingen");
}