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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combineing form output

Status
Not open for further replies.

pheos2

Technical User
Jul 22, 2003
19
GB
I’m not that good with PHP, so please forgive me.
I’m working in dreamweaver to create a data entry form.
I have a number of check boxes and I want to send their combined value to one field in my SQL database.

For example:
The Fist checkbox would have the checked value of 'Item 1'
The Second checkbox would have the checked value of 'Item 2'
The third checkbox 'Item 3' and so on.

When the form is submitted the value placed into the database would be 'Item 1 Item 2 Item 3' assuming all the boxes were ticked.

I have tried it with a simple form. I set the names of all the checkboxes to the same and submitted it to a php page which then displayed the URL Variable.

The second page only displays the value of the last checkbox in the form regardless of how many are checked.

I have read on google groups than putting [] at the end on each element name will combine the values however this only gives me 'array' which I just don’t know what to do with:)

Is it possible to combine the values of the checkboxes when processing the form?

Cheers
 
And yes I know I misspelled the title!!
 
Plce the [] at the end of the name so you get the array element when looking at it. Everything is combined into an array which you then can manipulate with:
Code:
    [COLOR=red]//check for options and assign as needed to myOpts[/color]
    $options= $_POST['options'];
    [COLOR=red]//count the number of elements[/color]
    $numOpts = count($options);
    [COLOR=red]//if more than one, implode with a comma to create a csv value for the db[/color]
    if ($numOpts>1){
       $myOpts=implode(",",$options);
    [COLOR=red]//if just one then let that value = the var on this side[/color]
    }elseif ($numOpts==1){
       $myOpts=$options;
    }else{
       [COLOR=red]//if empty set the local var to nothing[/color]
       $myOpts="";
     }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top