MozazDesign MozazDesign - 1 year ago 93
SQL Question

How to use $_GET to get multiple parameters using the same name in PHP

I'm just starting PHP so bare with me..

I'm using checkboxes to search a mysql database I have created. As the checkboxes all use the same name, when I use $_GET, it only gets the last value in the URL.

For example:

would only return Items, and would override Textures.

Is there a way to store both the values, and then to use these values to search my database?

Thanks in advance!

Answer Source

PHP is a little odd here. Using its standard form data parser, you must end the name of the controls with [] in order to access more than one of them.

<input type="checkbox" name="foo[]" value="bar">
<input type="checkbox" name="foo[]" value="bar">
<input type="checkbox" name="foo[]" value="bar">

Will be available as an array in:


If you don't want to rename the fields, then you will need to get access to the raw data ($_SERVER['REQUEST_URI']) and parse it yourself (not something I'd recommend).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download