本文介绍了将复选框值存储到 mysql 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我在 mysql db 中存储复选框值时遇到问题(只有最后一个值存储在数据库中).如何修复此代码以存储所有选中的值?
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')";
?>
推荐答案
你可以使用 implode http://php.net/manual/en/function.implode.php
$q1=implode(',', $_POST['q1']);
这篇关于将复选框值存储到 mysql 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)