How to insert checkbox values to mysql
Hi all i got a form with a few checkbox on it. User select a few of checkboxes and and press a button to write their values to db. But i do not know how to write it to mysql db. I be happy if an expert help me with that.Thanks
Note:Assuming the table has one columns which is for id value
code for check box form
Code:
<form action="./write.php" method=post >
<input type="checkbox" name="id" value="1"
<input type="checkbox" name="id" value="2"
<input type="checkbox" name="id" value="3"
<input type="submit" value="Add this/these Songs to my PlayList" name="B1">
Re: How to insert checkbox values to mysql
Quote:
Originally Posted by tony007
Code:
<form action="./write.php" method=post >
<input type="checkbox" name="id" value="1"
<input type="checkbox" name="id" value="2"
<input type="checkbox" name="id" value="3"
<input type="submit" value="Add this/these Songs to my PlayList" name="B1">
If you are only allowing the user to select 1 checkbox, you just need to pass the value of $id. If you are letting them select as many as you want, since you are using an array, just write all the values like so, $id[1], $id[2] etc.
Have a variable like "$checkbox" and then just say "$checkbox = $id[1] "," $id[2] "," $id[3] and so forth. When writing to the database, just use $checkbox and it will write the string "val1,val2,val3". When you want to call the individual numbers out of the database later, use the explode function to get each number.