Confusion with exact syntax of $_POST variable names

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
timbokil
Forum Newbie
Posts: 1
Joined: Thu Sep 20, 2007 3:58 am

Confusion with exact syntax of $_POST variable names

Post 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!
Hemlata
Forum Commoner
Posts: 35
Joined: Mon Sep 10, 2007 5:40 am
Location: India
Contact:

Post by Hemlata »

Hello,

Modify code with the following.

Code: Select all

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

Regards,
mad_phpq
Forum Commoner
Posts: 85
Joined: Fri Apr 27, 2007 5:53 am

Post 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]'];
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post 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.
mad_phpq
Forum Commoner
Posts: 85
Joined: Fri Apr 27, 2007 5:53 am

Post by mad_phpq »

oh i see. wasnt sure it would copy across. :)
Post Reply