On Thu, Mar 11, 2004 at 02:51:25PM +0000, Mike Mapsnac wrote:
> I have about 10 fields in the form. And I get the fields through POST:
> //Get Variable from the form
> $username = $_POST['username'];
> $password = $_POST['password'];
> $password2 = $_POST['password2'];
> $email = $_POST['email'];
> $email2 = $_POST['email2'];
> $nickname = $_POST['name'];
> $city = $POST['city'];
> $state = $_POST['state'];
> $country = $_POST['country'];
> $misc = $_POST['misc'];
> $country = $_POST['country'];
> 
> It works but it looks ugly. For each variable I have statemet. Is there a 
> way to get the variables in the loop?

In addition to the other suggestions, you might use extract() on $_POST:

  http://www.php.net/extract

To be sure you know where you're getting your variables, you could add a
prefix to the variable names ('p', for example), so your vars would look
like:

  $p_username
  $p_password
  $p_password2
  etc...

I personally would prefer this over register_globals because it gives me
more convenient access to my variables, but I don't have the danger of
$_POST variables overwriting my existing ones (assuming I don't name
other variables with the p_ prefix, use the proper extract() flags, etc.).

joel

-- 
[ joel boonstra | gospelcom.net ]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to