Page 1 of 1
checkboxes with $_GET
Posted: Mon May 01, 2006 4:27 am
by pedrotuga
ok... first of all... can i send and get checkboxes values to/from $_GET just like $_POST or is there some issues?
i am using this code on the form
Code: Select all
<form name="form1" method="get" action="index.php">
<$php
querydb="select * from uploadsites";
$result=mysql_query($querydb);
while ( $array=mysql_fetch_array($result) ){
echo "<input type=\"checkbox\" name=\"".array[]." value=\"".$array["id"]."\">". $array["name"].
"<br>";
}
?>
</form>
but i am having troubles figuring out where to get the values from.
shouldnt they be in
?
btw, what's the easyest way to print an associative array?
Posted: Mon May 01, 2006 4:31 am
by s.dot
#1. simply using array() as the field name will not work. You'll have to give it a name and add [] after it. For example,
Code: Select all
<input type="checkbox" name="box[]">
If you passed that using $_GET, your url would look something like this
page.php?box=x&box=y&box=3&box=4&box=43
Depending on the amount of checkbox values you had.
The best way is to use $_POST.
I'm not sure what will happen if you print_r($_GET['box']); but you could test it out and see if you get your values into an array.
Posted: Mon May 01, 2006 4:45 am
by pedrotuga
I had some errors using the quotes...
it was echoing somthin like
thx for the printinig tip... btw it outputs something like this
Array ( [0] => 2 [1] => 4 [2] => 5 )
thanks scott
Posted: Mon May 01, 2006 4:57 am
by s.dot
Yeah, you'll have errors using the quotes if you don't escape them properly. You would want to do something like this:
Code: Select all
echo "<input type=\"checkbox\" name=\"box[]\" value=\"".$array['id']."\">";
And since it is working apparently by your output.. you could assign a variable to the array.
Re: checkboxes with $_GET
Posted: Mon May 01, 2006 6:54 am
by someberry
pedrotuga wrote:ok... first of all... can i send and get checkboxes values to/from $_GET just like $_POST or is there some issues?
Don't forget that unchecked checkboxes will not get sent by the browser, which is very annoying for dynamically created checkbox names.
Re: checkboxes with $_GET
Posted: Mon May 01, 2006 7:37 am
by pedrotuga
someberry wrote:pedrotuga wrote:ok... first of all... can i send and get checkboxes values to/from $_GET just like $_POST or is there some issues?
Don't forget that unchecked checkboxes will not get sent by the browser, which is very annoying for dynamically created checkbox names.
thats actually ok for me... i notice that and its cool..
this way i can loop the array containing the ids of the elements checked at once.