Jump to content

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.