0

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?

10
  • ['identity_number'] => ['account'] => they seem undefined to me Commented Nov 17, 2014 at 14:01
  • @MarcoMura values seems undefined but keys are still present Commented Nov 17, 2014 at 14:02
  • @MarcoMura they are defined but no value assigned Commented Nov 17, 2014 at 14:02
  • The values are undefined, yes, but the index is not. Its also throwing the undefinex index error on indexes containing values Commented Nov 17, 2014 at 14:02
  • When I use print_r, I do not see quotes. I see something like [key] => value. Because you are seeing quotes, it tells me that you have quotes embedded into the key values - or you typed this by hand and added the quotes. If the quotes are in the key values, as shown, the keys without the quotes are not defined. Commented Nov 17, 2014 at 14:05

2 Answers 2

4

If that's the output of print_r() the data that was sent in the POST request has quotes around the key names; to access the data now you would have to do this:

echo $lines["'name'"];

Alternatively, and more preferably, find out why those extra quotes are transferred and remove them.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, thats the case indeed =)
0

You have an error in your code. You are using => instead of = in your query code.

2 Comments

However, the problem of undefined indexes still consist
If something is wrong in the question that does not directly address the actual question, or is unrelated to the question, do not post a solution for that as an answer, but instead post a comment. Answers to a question should answer that question, not random things you found lying around that might be possibly remotely useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.