我想在选中复选框并提交表单时将文本框值发布到数据库中,我该怎么做。我的代码片段是,
html:
<form name="form1" method="post" enctype="multipart/form-data">
<td>Accessories with computer<br>
Power Adapter<input type="checkbox" name="accessories[]" value="power adapter"><br>
Power Cord<input type="checkbox" name="accessories[]" value="power cord"> <br>
Monitor<input type="checkbox" name="accessories[]" value="monitor"><br>
Keyboard<input type="checkbox" name="accessories[]" value="keyboard"><br>
Mouse<input type="checkbox" name="accessories[]" value="mouse"><br>
<input type="text" size="10" name="others1" class="input-text" />
<input type="checkbox" name="accessories[]" value="<?= $_POST['others1'];?>" ><br>
<input type="text" size="10" name="others2" class="input-text" /><input type="checkbox" name="accessories[]" value="<?=$_POST['others2'];?>" ><br>
</td>
</tr>
</form>
php:
$accessories = implode(' ', $_POST['accessories']);
$query ="INSERT INTO ticket SET accessories = '$accessories'";
$result = mysql_query($query);
我也尝试将复选框值作为变量传递,但值未存储在数据库中。请给我建议。
表格的部分看起来像,