Announcement

Collapse
No announcement yet.

Not sure why I am getting offset error

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Not sure why I am getting offset error

    Hi All,

    I have an app that uploads a csv file and allocates it's contents to some fields and then saves them to a table.

    It saves the records to the table OK, but I get an error message that states there is 4 offset errors some being :1 and others :2

    I have no idea where I have gone wrong (maybe forest for the trees sort of thing)

    Here is the code that uploads and saves the data

    Code:
    if ({bank_code} == 0){
    	// do nothing
    }else{	
    $cnt=0;
    $handle = fopen({csv_file},"r");
    if ($handle)
    {
    set_time_limit(0);
    
    //loop through one row at a time
    while (($data = fgetcsv($handle, 4096, ',')) !== FALSE)
    {
    
    $date_check = $data[{date_col}-1];
    // check for single day digits	
    if ($date_check[1] == '/'){
    	$date_check = '0'.$date_check;
    	//echo $date_check;
    }
    $_date = sc_date_conv($date_check,"dd/mm/yyyy","db_format");
    
    $_amount = ABS($data[{amount_col}-1]);
    
    if ($data[{amount_col}-1] < 0) {
    	$_drcr = 1;
    }else{
    	$_drcr = -1;
    }
    
    if ($data[{amount_col}-1] < 0) {
    	$_type = 1;
    }else{
    	$_type = 0;
    }
    
    $_payee = $data[{ref_col}-1];
    
    $_bank = {bank_code};	
    $_not_balanced = 1;
    	
    $stm ="INSERT INTO temp_transactions (tp_date,tp_amount,tp_payee,tp_drcr,tp_bank,tp_type,tp_not_balanced)
           VALUES ('{$_date}',{$_amount},'{$_payee}',{$_drcr},{$_bank},{$_type},{$_not_balanced})";
    
    sc_exec_sql($stm);
    
    $cnt++;
    }
    
    fclose($handle);
    }
    
    [count_imported] = $cnt;
    
    }
    					
    sc_redir('form_temp_transactions',,"_parent");
    I also have attached the error message - the program stops before the sc_redir as that app is never started only the error message

    Thanks

    Tonyoffset_error01.jpg

  • #2
    I have partially sorted it, not the error message, that still appears but it does not prevent the program form performing it's sc_redir()

    For some reason, my csv files must be missing something, as the code still believed that there was a final row, only with no values, and so the SQL threw an error on the date field being a null. I added extra checking, to only allow the insert if there was a value to be saved.

    So, still do not know what the error is, but it is only visible for a moment, and disappears when the next window opens.

    Tony

    Comment

    Working...
    X