Page 1 of 1

Confusion with exact syntax of $_POST variable names

Posted: Thu Sep 20, 2007 6:10 am
by timbokil
I'm building a form containing input types like

Code: Select all

<input type="text" size="4" maxlength="13" name="34[high]">
and expecting to be able to address the results once the form is processed as a PHP variable called

$_POST[34][high]

but I'm getting the error

Code: Select all

Undefined variable:  $_POST[34][high]
Have I got something wrong with the variable name, or is the error elsewhere?

Thanks!

Posted: Thu Sep 20, 2007 6:47 am
by Hemlata
Hello,

Modify code with the following.

Code: Select all

echo $_POST['34']['high'];
Hope this will solve your problem.:)

Regards,

Posted: Thu Sep 20, 2007 7:46 am
by mad_phpq
why are you naming it name="34[high]" ??

You should only be able to call it like this

echo $_POST['34[high]'];

Posted: Thu Sep 20, 2007 7:55 am
by maliskoleather
mad_phpq wrote:You should only be able to call it like this

echo $_POST['34[high]'];
no. PHP automatically re-assigns anything with a [] in the name to an array. therefore

Code: Select all

<input name="foo[bar]" value="baz" />
becomes

Code: Select all

$_POST['foo']['bar'] == 'baz';


also, doing something like

Code: Select all

var_dump($_POST);
at the beginning of your file may come in handy to see if the variable is actually getting set.

Posted: Thu Sep 20, 2007 7:57 am
by mad_phpq
oh i see. wasnt sure it would copy across. :)