Re: Get "nice" variables from POST
| From: | Rob Adams | Date: | Thu, 11 Mar 2004 18:22:40 +0000 |
| Subject: | Re: Get "nice" variables from POST | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-180202@lists.php.net to get a copy of this message | ||
"Mike Mapsnac" <mikerh9@hotmail.com> wrote in message
news:BAY15-F4qKonKUa0NSu00077d2a@hotmail.com...
>
>
> >From: Marek Kilimajer <kilimajer@webglobe.sk>
> >
> >$fields = array('username', 'password', ...);
> >foreach($fields as $key) $$key = $_POST[$key];
> >
> Thanks.
>
> It looks much nicer :)
Along the same lines, I've found this helpful when inserting into mysql.
foreach($_POST as $key => $val)
$$key = mysql_escape_string($val);
Or, to use Marek's trick of only using certain variables:
$fields = array('username', 'password', ...);
foreach($fields as $key)
$$key = mysql_escape_string($_POST[$key]);
I like that a lot better.
-- Rob