-
$_POST[$$variablename]
I really need to be able to refer to the values of variables sent to my script by the POST method... But I need to build the variable name first in my script.
This is what I thought would work:
$variablename="number".1;
$value1=$_POST[$$variablename];
But it doesn't seem to work.
How can I get the value of this variable?
Paul
-
PHP Code:
$varname = ${number.1};
$vaue1 = $_POST['$varname'];
Try that, just off the top of my head
-
PHP Code:
$value = $_POST[$varname]
-
Antartican, I believe you want something like the following example:
PHP Code:
for ($x = 1; $x < 5; $x++)
echo $_POST['var' . $x] . "<BR>";
Keep in mind that you might be better off posting the form using an array. Example form:
PHP Code:
<input type="checkbox" name="box[]">
<input type="checkbox" name="box[]">
<input type="checkbox" name="box[]">
<input type="checkbox" name="box[]">
Then in your PHP the values will be assigned as an array:
PHP Code:
print_r($_POST['box'])
You will get all the values. Hope that helps!
-
-
It depends on what exactly your trying to do...
Say you posted...
<input type="hidden" name="test" value="haha" />
If you wanted $test to == 'haha' then do the following:
PHP Code:
foreach($_POST as $key => $val)
$$key = $val;
If you wanted $haha to == 'test'
PHP Code:
foreach($_POST as $key => $val)
$$val = $key;
You have unlimited possibilities of what you can do in php, so just figure out exactly what you need it to do and we can show you how to do it :)
-
big thanks
Thanks for giving me quite a few options!! I went for tmiller04s first option which did exactly what I needed it to.:)
-
-
PHP Code:
foreach($_POST as $key => $val)
$$key = $val;
That is exactly what extract() does.