Jump to content

php and form variables


whiterecluse

Recommended Posts

Is there an easy way to retrieve all of the variables from a form? Using $_POST for every variable would take a lot of code for what I wanna do. I'm hoping theres a way I can do it by using this code or a variation of it:
[code]
foreach($HTTP_POST_VARS as $key => $val)
{
//do something with the val....
}
[/code]

Pointing me to any tutorials would be great too :)
Link to comment
https://forums.phpfreaks.com/topic/31430-php-and-form-variables/
Share on other sites

That's what I thought I needed to use but I can't seem to grasp the concept.
$$key = $val;
does this mean that a variable named $val1 will be stored in $$key?

What I want is to be able to compare the value of one variable against the value of another using variable variables (I think I would use them)
If you're form had two fields, [i]username[/i] and [i]realname[/i] and I submitted the form with my details (HuggieBear and Richard) then PHP would get the following variables:

[code=php:0]$_POST['username']
$_POST['realname'][/code]

If you want a these to be variables with the same name as the key, then do this...

[code]<?php
foreach($_POST as $key => $value)
     $$key = $value;
?>[/code]

This means that if I want to echo Richard I can type [code=php:0]echo $realname;[/code] not [code=php:0]echo $$key;[/code]

The above code has created variables with the names of the keys of the $_POST array.

Regards
Huggie

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.