/    Sign up×
Community /Pin to ProfileBookmark

How to insert checkbox values to mysql using php

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″>

[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@chazzyFeb 22.2006 — change input names to "id[]"

close your input tags.

and on "write.php" look at the array $_POST['id'][].
Copy linkTweet thisAlerts:
@SheldonFeb 22.2006 — <i>
</i>&lt;form action="./write.php" method=post &gt;

&lt;input type="checkbox" name="id1" value="1"
&lt;input type="checkbox" name="id2" value="2"
&lt;input type="checkbox" name="id3" value="3"

&lt;input type="submit" value="Add this/these Songs to my PlayList" name="B1"&gt;

[/QUOTE]

write.php
[code=php]
isset($_GET['id1']) id1 == $_GET['id1'];
isset($_GET['id2']) id2 == $_GET['id2'];
isset($_GET['id3']) id3 == $_GET['id3'];

$id = $id1."-".$id2."-".$id3;

mysql_query("INSERT INTO table (id) VALUES ('$id')");
[/code]
Copy linkTweet thisAlerts:
@methodauthorFeb 22.2006 — <i>
</i>&lt;form action="./write.php" method=post &gt;

&lt;input type="checkbox" name="id1" value="1"
&lt;input type="checkbox" name="id2" value="2"
&lt;input type="checkbox" name="id3" value="3"

&lt;input type="submit" value="Add this/these Songs to my PlayList" name="B1"&gt;

[/QUOTE]

write.php
[code=php]
isset($_GET['id1']) id1 == $_GET['id1'];
isset($_GET['id2']) id2 == $_GET['id2'];
isset($_GET['id3']) id3 == $_GET['id3'];

$id = $id1."-".$id2."-".$id3;

mysql_query("INSERT INTO table (id) VALUES ('$id')");
[/code]
[/QUOTE]

Many thanks for u reply. Well i do no want to change my

<input type="checkbox" name="id1" value="1"

since there is any java script in same page that uses the check box values and one more thing the number of checkbox passed is dynamic not static. I be happy if some one help here.thanks
×

Success!

Help @method spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...