Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have problem in storing checkbox values in mysql db (only the last value is stored in the database). How can I fix this code to store all checked values?

<label class="q" for="q1">Which, if any, of these activities did you do on the Internet in the last 30 days? 
</label><br><br>
<input name="q1[]" type="checkbox" value="a1">Used e-mail<br>
<input name="q1[]" type="checkbox" value="a2">Used instant messenger & chat room<br>
<input name="q1[]" type="checkbox" value="a3">Made a purchase for personal use<br>
<input name="q1[]" type="checkbox" value="a4">Downloaded/Played a video game<br>
<input name="q1[]" type="checkbox" value="a5">Obtained news/information/current events<br>
<input name="q1[]" type="checkbox" value="a6">Looked for employment (Used classified listings)<br>
<input name="q1[]" type="checkbox" value="a7">Looked for recipes<br>
<input name="q1[]" type="checkbox" value="a8">Downloaded a movie<br>
<br>



<?php

include('config.php');

$tbl_name="temp_members_db";
$q1=$_POST['q1'];
$sql="INSERT INTO $tbl_name(q1)VALUES('$q1')";
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
297 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use implode http://php.net/manual/en/function.implode.php

$q1=implode(',', $_POST['q1']);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...