Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieving multiple checkbox values

Status
Not open for further replies.

riffy

Programmer
Mar 29, 2001
106
US
hey guys,

I have a form that has 5 checkboxes each with the same name but different values. The users can click on multiple checkboxes. Those values are inserted into a table in a database however they are entered as separate fields. I want to know whether there's a script to get the checkbox values and separate them using commas so that they can all be inserted into the same column.

thanks,
arif
 
foreach ($HTTP_GET_VARS["NAME_OF_YOUR_CHECKBOXES"] as $value)

{
print "selected: $value";

print &quot;<br>&quot;;

} ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
thanks karver but will that separate the checked values by commas or put them on separate lines?

and the query to insert into the database would be something like this???

Code:
foreach ($HTTP_GET_VARS[&quot;vol&quot;] as $value) {
  print &quot;selected: $value&quot;;
  print &quot;<br>&quot;;
  $sql=&quot;insert into skills (id, vol) values (NULL, '$value')&quot;;
  $result =  mysql_query ($sql);
}
 
the values some through as an array...

just implode the array

$myboxes = implode($myCheckboxName,&quot;,&quot;);

I actually put some if then statements around it to avoid imploding if there is only 1 active box for my application.

hth Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
switch the params orders.

implode first param is the separator, and the second is the array.
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top