本文介紹了將復(fù)選框值存儲到 mysql 數(shù)據(jù)庫的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
我在 mysql db 中存儲復(fù)選框值時遇到問題(只有最后一個值存儲在數(shù)據(jù)庫中).如何修復(fù)此代碼以存儲所有選中的值?
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']);
這篇關(guān)于將復(fù)選框值存儲到 mysql 數(shù)據(jù)庫的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!