How to insert checkbox values to mysql using php (1 Viewer)

tony007

Registered User.
Local time
Today, 11:31
Joined
Jun 30, 2005
Messages
53
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">
 

Dreamweaver

Well-known member
Local time
Today, 18:31
Joined
Nov 28, 2005
Messages
2,466
First You'll need to connect to the MySQL Database before you can even think of adding an update Query.
If Ya Search The MySQL Forums I'm sure You'll find what ya need to get ya started.

Mick
 

Vincenzo

New member
Local time
Today, 11:31
Joined
Aug 29, 2007
Messages
1
If you're planning of allowing multiple boxes to be checked, you should give each boxes their own unique "name" and each name must have their own column in your db table.

Example:

<input type="checkbox" name="ckbx1" value="">
<input type="checkbox" name="ckbx2" value="">
<input type="checkbox" name="ckbx3" value="">

Then in your PHP code, you should run a check for each boxes by giving them value before updating your database.

Example:

PHP:
if (ckbx1 != NULL) {
ckbx1 = 1;
}
else {
ckbx1 = 0;
}

Then in your database, the columns ckbx1, ckbx2, and ckbx3 will either have a 0 or a 1, where 0 is unchecked and 1 is checked.

If you choose to limit the choices to just one choice rather than multiple choices, try using a drop-down selection instead.

Example:

<select name="id">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

I hope that helps.
 

Users who are viewing this thread

Top Bottom