I have this code:
$array = 'user_profile';
$var_name = 'postcode';
if ( isset($_POST['user_profile']) ) {
echo '<br />Var name ('.$var_name.')<br />';
print '<pre>';print 'Keys<br>';print_r(array_keys($_POST[$array]));print '</pre>';print '<br />';
print '<pre>';print 'POST user_profile<br />';print_r($_POST[$array]);print '</pre>';print '<br />';
print '<pre>';print 'POST dump<br />';var_dump($_POST[$array]);print '</pre>';print '<br />';
echo '<br />{'.$_POST[$array][$var_name].'}<br /><br />';
}
die();
And I get this:
Var name (postcode)
Keys
Array
(
[0] => 'address_1'
[1] => 'address_2'
[2] => 'address_3'
[3] => 'address_4'
[4] => 'address_5'
[5] => 'postcode'
[6] => 'phone'
)
POST user_profile
Array
(
['address_1'] => Templeton House
['address_2'] => 62 Templeton Street, Suite 22
['address_3'] =>
['address_4'] => Glasgow
['address_5'] =>
['postcode'] => G40 1DA
['phone'] => 07222222
)
POST dump
array(7) {
["'address_1'"]=>
string(15) "Templeton House"
["'address_2'"]=>
string(29) "62 Templeton Street, Suite 22"
["'address_3'"]=>
string(0) ""
["'address_4'"]=>
string(8) "Glasgow "
["'address_5'"]=>
string(0) ""
["'postcode'"]=>
string(7) "G40 1DA"
["'phone'"]=>
string(8) "07222222"
}
Notice: Undefined index: postcode in C:\xampp\htdocs\xxxxxx.com\src\controller\app\userController.php on line 153
{}
Line 153 is the one with: echo '<br />{'.$_POST[$array][$var_name].'}<br /><br />';
I have been all morning trying to find out where is my mistake.
Can somebody help me?. Thanks.
[EDIT]
I made some changes to try to clearify what has been asked. Obviously the code is more long but the bit you see is at the begining of the function. There is nothing else to show you that will help to understand what is hapening. The output is exactly what I get in the browser, even the last brackets, by the way I don't understand why are there, the first one is OK but the second is printed after a NOTICE ???.