Skip to main content
1 of 2
Ole Haugset
  • 3.8k
  • 3
  • 27
  • 48

PHP Array Notice undefined index - Its defined?

Im having problems wrapping my head around a code that I mean should work fine.

Here is the code:

 foreach( $_POST['wageline'] AS $line ){ print_r( $line ); if( !$MySQL->Query(" INSERT INTO wages_lines SET 'batch_id' = '" . $this->batch_id . "', 'name' => '" . $line['name'] . "', 'identity_number' => " . $line['identity_number'] . "', 'account' => '" . $line['account'] . "', 'phone' => '" . $line['phone'] . "', 'ordinary_hours' => '" . $line['ordinary_hours'] . "', 'fifty_percent' => '" . $line['fifty_percent'] . "', 'hundred_percent' => '" . $line['hundred_percent'] . "', 'mileage' => '" . $line['mileage'] . "', 'remuneration' => '" . $line['remuneration'] . "', 'pall_dag_2' => '" . $line['pall_dag_2'] . "', 'pall_dag_3' => '" . $line['pall_dag_3'] . "', 'pall_natt_2' => '" . $line['pall_natt_2'] . "', 'pall_natt_3' => '" . $line['pall_natt_3'] . "', 'ub_1' => '" . $line['ub_1'] . "', 'ub_2' => '" . $line['ub_2'] . "', 'ub_3' => '" . $line['ub_3'] . "', 'ub_4' => '" . $line['ub_4'] . "', 'ub_5' => '" . $line['ub_5'] . "', 'employee_wage' => '" . $line['employee_wage'] . "', 'brutto_total' => '" . $line['brutto_total'] . "', 'mileage_total' => '" . $line['mileage_total'] . "', 'remuneration_total' => '" . $line['remunerations_total'] . "' ") ) 

The result of my print_r is as following:

Array ( ['name'] => Alexander Fagerstrand ['identity_number'] => ['account'] => ['phone'] => 0 ['ordinary_hours'] => 32.5 ['fifty_percent'] => 0 ['hundred_percent'] => 0 ['mileage'] => 458 ['remuneration'] => 628 ['pall_dag_2'] => 0 ['pall_dag_3'] => 0 ['pall_natt_2'] => 0 ['pall_natt_3'] => 0 ['ub_1'] => 0 ['ub_2'] => 0 ['ub_3'] => 0 ['ub_4'] => 0 ['ub_5'] => 0 ['employee_wage'] => 177 ['brutto_total'] => 5752.50 ['mileage_total'] => 1854.9 ['remunerations_total'] => 628 ) 

And still, Im getting notices as these:


Notice: Undefined index: name in /var/www/vhosts/ontimebemanning.no/portal.ontimebemanning.no/modules/core.wages/classes/wage.class.php on line 573

Notice: Undefined index: identity_number in /var/www/vhosts/ontimebemanning.no/portal.ontimebemanning.no/modules/core.wages/classes/wage.class.php on line 574

Obviously, they are defined, so I have no clue why my script is throwing notices at my face. Anyone got a clue?

Ole Haugset
  • 3.8k
  • 3
  • 27
  • 48