Page 1 of 1

$_GET with no value

Posted: Sun Mar 28, 2010 4:12 pm
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

Re: $_GET with no value

Posted: Sun Mar 28, 2010 7:45 pm
by requinix
First: use

Code: Select all

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

Second: array_filter