PHP 数组通知未定义的索引 - 它已定义


PHP Array Notice undefined index - Its defined?

我在理解我的意思应该可以正常工作的代码时遇到问题。

这是代码:

        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'] . "'
            ") )

我的print_r结果如下:

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
)

尽管如此,我还是收到了以下通知:

注意:未定义的索引:名称在/var/www/vhosts/ontimebemanning.no/portal.ontimebemanning.no/modules/core.wages/classes/wage.class.php573
注意:未定义的索引:identity_number 在/var/www/vhosts/ontimebemanning.no/portal.ontimebemanning.no/modules/core.wages/classes/wage.class.php574

显然,它们是定义的,所以我不知道为什么我的脚本会向我的脸抛出通知。有人知道了吗?

如果这是print_r()的输出,则在 POST 请求中发送的数据在键名两边有引号;现在要访问数据,您必须这样做:

echo $lines["'name'"];

或者,更优选的是,找出为什么转移这些额外的报价并删除它们。

您的代码中有错误。您在查询代码中使用=>而不是=