How to store data from a multiple check box form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • haripadadas
    New Member
    • May 2010
    • 2

    #1

    How to store data from a multiple check box form

    I have 6 checkbox in my entryform.php. I am supposed to check more than 1 checkbox at a time. How to store multiple value in single column of database?

    Latter I also retrieve value from database and EDIT the form
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    #2
    you could use a loop that creates a string with the values seperated by commas then insert the final string into the database. when you want to retrieve you would use the explode() function to seperate the data into an array by the commas. if you have six boxes i'd use the for loop below so it counts through but you should also check if your $_POST vars are set before add them into your string as you will just make a string that might look like the one below with blanks

    $string = data,,data,data ,,

    Code:
    //explode
    $array = explode(",",$string);
    
    //loop
    for($i=0;$i<7;$i++){
    }

    Comment

    Working...