$_GET with no value

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
andrew_hodgson
Forum Newbie
Posts: 9
Joined: Fri Mar 12, 2010 9:09 am

$_GET with no value

Post by andrew_hodgson »

I'm got a form on my search page with passes a varying number of variables to my results page. What I want to do is to extract the array key and make it the name of that variable and the value passed the value, ie,

$_GET = Array ([param1] => 10, [param2] => 20 ....... etc)

and covert that into,

$param1 = 10;
$param2 = 20;
...
...
etc.

I've got that working fine with this code,

Code: Select all

while ($value = current($_GET)) {
$term = key($_GET);
$value = mysql_prep($value);
$$term = $value; 
next($get);
}
I've got to do it like that as the number of parameters in the GET array can change depending on how the form is filled out.

I want to let people omit a value in the forum but I get problems when say, param1 is passed through WITH NO VALUE, ie,

$_GET = Array ([param1] =>, [param2] => 20 ....... etc)

In this case the user hasn't filled in param1.

The code I've done seems to break down,

Any thoughts??? Suggestions on how to do this way efficiently are also greatly welcomed

Thanks,


Andrew
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: $_GET with no value

Post by requinix »

First: use

Code: Select all

<input ... name="param[]" ...>
Then $_GET["param"] will be an array.

Second: array_filter
Post Reply