Page 1 of 1
Confusion with $_REQUEST array data
Posted: Fri Apr 24, 2009 9:59 pm
by Stuartc
Hi, I'm obviously new here, so ... BE NICE!
Basically I'm taking data posted from several arrays of text boxes on a HTML form. The key/val pair then get sent to myfunction which puts it all into an SQL table. Works great!
Code: Select all
foreach ($_REQUEST as $key=>$val)
{
$$key = "$val";
$id = $key;
$myvals = $val;
myfunction($id,$myvals);
}
The issue, now I need to do some tests on $id (ie. if ($id == 56) don't run myfunction) but I can't seem to access it. It goes into the SQL table fine and if I retrieve it I can then see the data. I have played around with while list each etc, but I just end up getting the same results with different code.
I'm really confused, what am I missing?
Thanks
Re: Confusion with $_REQUEST array data
Posted: Fri Apr 24, 2009 10:20 pm
by kaiser0427
have you tried
Code: Select all
if ($id !=$some_var) { // where $some_var = any condition you want
myfunction($id,$myvals);
} else {
//display some error message or run another function
}
this will run your function if $id is not equal to what ever your condition is in $some_var
I may be misunderstanding what you are asking if this doesn't help
Re: Confusion with $_REQUEST array data
Posted: Fri Apr 24, 2009 10:53 pm
by Stuartc
Yeah, that's what I'm doing. The thing is I understand
how to do it, but I need to see the hidden data.
What i don't get is if I have a form with text boxes on it that posts like this...
(the key/value pairs for the text boxes are hidden - I get that)
and runs code like this
Code: Select all
foreach ($_REQUEST as $key=>$val)
{
$$key = "$val";
$id = $key;
$myvals = $val;
echo "$id = $myvals<br>";
myfunction($id,$myvals);
}
it will echo
Code: Select all
action=update
stage=1
__utma = 131175305.1111354728.1239403329.1239403329.1239403329.1
__utmz = 131175305.1239403329.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)
My data from the text boxes is missing, yet it runs through myfunction and updates the SQL table.
Why don't they echo?
Thanks for replying kaiser0427

No longer confused Re: Confusion with $_REQUEST array data
Posted: Sat Apr 25, 2009 4:33 am
by Stuartc
Well confused with myself.
The mistake was in the code.
After half a bottle of whiskey, I have figured it out.
The form was posting what I wanted, the way I wanted and allowing me to manipulate it.
I was reading the data
before the form was posted.

Duh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
