例如这样的复选框
一般字段名设置成数组形式,而MySQL数据库中为字符型,这就需要将数组组合成字符串。
<tr bgcolor="#FFCC33">
<td height="25" align="right">爱好:</td>
<td height="25" align="left"><input name="fond[]" type="checkbox" value="电脑">
电脑
<input name="fond[]" type="checkbox" value="音乐">
音乐
<input name="fond[]" type="checkbox" value="旅游">
旅游
<input name="fond[]" type="checkbox" value="其他">
其他</td>
</tr>
for($i=0;$i<count($_POST['fond']);$i++)
$array[$i]=$_POST['fond'][$i];
$str=implode(',',$array);//implode()函数将数组组合成字符串
$sql2="insert into message(User,Sex,Password,Xueli,Hobby,Photo,Intro) values('$_POST[user]','$_POST[sex]','$_POST[pwd]','$_POST[select]','$str', '$path','$_POST[intro]')";