我有这样的形式:如何在数据库中保存复选框数组?
<tr>
<td><input type="hidden" name="ledlamps" value="LED lamps">LED lamps:</td>
<td><input class="field checkbox" type="checkbox" name="box[]" value="3mm"/><label class="choice">3mm</label></td>
<td><input class="field checkbox" type="checkbox" name="box[]" value="5mm"/><label class="choice">5mm</label></td>
<td><input class="field checkbox" type="checkbox" name="box[]" value="8mm"/><label class="choice">8mm</label></td>
<td><input class="field checkbox" type="checkbox" name="box[]" value="10mm"/><label class="choice">10mm</label></td>
<td><input class="field checkbox" type="checkbox" name="box[]" value="Ovals"/><label class="choice">Ovals</label></td>
<td><input class="field checkbox" type="checkbox" name="box[]" value="Assembly LEDs"/><label class="choice">Assembly LEDs</label></td>
</tr>
这PHP代码:
$box=$_POST['box'];
$ledlamps = $_POST['ledlamps'];
if ($box != 0) {
echo "$ledlamps: ";
while (list ($key,$val) = @each ($box)) {
$val1 = "$val, ";
echo "$val1";
}
}
如果回声它显示在我的方式输出,我希望它:
LED灯具:3毫米的5mm ,8毫米(如果我勾选相应的复选框)
但我想把它存储在一个MySQL表字段。我怎么做?
感谢您的帮助!
使用'serialize'函数:) – Sarfraz 2010-09-02 15:01:04