Confusion with $_REQUEST array data

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
Stuartc
Forum Newbie
Posts: 3
Joined: Fri Apr 24, 2009 9:45 pm

Confusion with $_REQUEST array data

Post 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
kaiser0427
Forum Newbie
Posts: 9
Joined: Thu Apr 23, 2009 3:38 pm

Re: Confusion with $_REQUEST array data

Post 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
Stuartc
Forum Newbie
Posts: 3
Joined: Fri Apr 24, 2009 9:45 pm

Re: Confusion with $_REQUEST array data

Post 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...

Code: Select all

index.php?action=update&stage=1
(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 :D
Stuartc
Forum Newbie
Posts: 3
Joined: Fri Apr 24, 2009 9:45 pm

No longer confused Re: Confusion with $_REQUEST array data

Post 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.
:banghead: Duh!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :banghead:
Post Reply