Trying to use a concatenated constant in $_POST

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
McManCSU
Forum Newbie
Posts: 22
Joined: Mon Apr 23, 2007 6:30 pm

Trying to use a concatenated constant in $_POST

Post by McManCSU »

I get an undefined index in this example:

Lets say that I do a print_r($_POST) and I verify that $_POST has some value:

Code: Select all

Array 
(
    [testExample] => thisIsAnExample
)
Here is the implementation:

Code: Select all

define('XYZ_TEST', 'testExample');

function One()
{
     functionTwo("XYZ");
}

function Twp($prefix)
{
    $input = $prefix . '_TEST';
    echo 'Post variable=' . $_POST[$input] . ' gives an undefined index';
}
I have tried doing things such as trimming the $input variables and stripping single and double quotes, but still nothing...

I should note that if I set up $input to be "testExample", all works fine, but since this is not using the constant properly I can't do it this way.

Thanks!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

define('XYZ_TEST', 'testExample');

function One()
{
  Two("XYZ");
}

function Two($prefix)
{
  $input = constant($prefix . '_TEST');
  echo 'Post variable=' . $_POST[$input];
}

// test
$_POST = array('testExample'=>'abc');
One();
McManCSU
Forum Newbie
Posts: 22
Joined: Mon Apr 23, 2007 6:30 pm

Post by McManCSU »

Awesome, thanks a lot!
Post Reply