Quetysis
asked on
Is it possible to assign a variable dynamically from a form request?
Not sure if what I want to do is possible. I want to loop through and set my variables from the form request for my check boxes. I have my check box variable named stored in a variable. Here's what I'm trying to do:
for ( $i = 1; $i <= 10, $i++ ) {
$var = 'chkbox' . $i;
if (isset($$var)) {
$_REQUEST['$$var']
}
}
for ( $i = 1; $i <= 10, $i++ ) {
$var = 'chkbox' . $i;
if (isset($$var)) {
$_REQUEST['$$var']
}
}
Agreed, however it is best to use either $_POST or $_GET to retrieve the data, as that way you know where the data is coming from.
And remember... NEVER TRUST USER INPUT, EVER, EVER, EVER........... NEVER!
Always filter/sanitize your input and escape your output.
And remember... NEVER TRUST USER INPUT, EVER, EVER, EVER........... NEVER!
Always filter/sanitize your input and escape your output.
ASKER
Hi steelseth12! I will give that a shot and report back. Thanks. I'm new to PHP so I was wonder if you and NickVd could clarify what NickVd was saying about filtering and sanitizing the data. Also, what is the difference between using $_REQUEST and $_POST or $_GET ?
Thanks!
Thanks!
ASKER
Ok, I had a chance to try out the suggestion above and it is not going to work for what I am asking. Any more ideas?
ASKER
Instead of specifying the variable assignment like this:
print $_REQUEST['firstname'];
I want to do this:
print $_REQUEST['$$var']
Where $$var will earlier be assigned to be firstname. Make sense?
print $_REQUEST['firstname'];
I want to do this:
print $_REQUEST['$$var']
Where $$var will earlier be assigned to be firstname. Make sense?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Steelseth12!
I figured out my problem when I went back and re-read the PHP documentation on variable variables for the 5th time. ug... Anyway, thanks for your help and for the explaination. It was much appreciated. :-)
I figured out my problem when I went back and re-read the PHP documentation on variable variables for the 5th time. ug... Anyway, thanks for your help and for the explaination. It was much appreciated. :-)
for ( $i = 1; $i <= 10; $i++ ) {
$var = 'chkbox' . $i;
if (isset($_REQUEST[$var])) {
print $_REQUEST[$var];
}
}