我的代码中有这个复选框
<fieldset><legend>What search engine do you prefer?</legend><br><br><br>
<!-- container ko start -->
<div id="container2">
<table>
<tr>
<td width="30%">
<label><img src="images/google.png" height="40px" width="120px"></label>
<input type="checkbox" name="engine1[]" value="google">
</td>
<td width="30%">
<label><img src="images/yahoo.png" height="40px" width="120px"></label>
<input type="checkbox" name="engine1[]" value="yahoo">
</td>
<td width="30%">
<label><img src="images/bing.png" height="40px" width="120px"></label>
<input type="checkbox" name="engine1[]" value="bing">
</td>
</tr>
</table>
</div>
</fieldset>
<br><br><br><br><br>
<fieldset><legend>Put check on the icons that you are familiar with.</legend><br><br><br>
<div id="container2">
<table>
<tr>
<td>
<label><img src="images/fb.png" height="40px" width="40px"></label>
<input type="checkbox" name="engine2[]" value="fb">
</td>
<td>
<label><img src="images/twit.png" height="40px" width="40px"></label>
<input type="checkbox" name="engine2[]" value="twitter">
</td>
<td>
<label><img src="images/googplus.png" height="40px" width="40px"></label>
<input type="checkbox" name="engine2[]" value="googleplus">
</td>
</tr>
<tr>
<td>
<label><img src="images/link.png" height="40px" width="40px"></label>
<input type="checkbox" name="engine2[]" value="linkedin">
</td>
<td>
<label><img src="images/pin.png" height="40px" width="40px"></label>
<input type="checkbox" name="engine2[]" value="pinterest">
</td>
<td>
<label><img src="images/del.png" height="40px" width="40px"></label>
<input type="checkbox" name="engine2[]" value="delicious">
</td>
</tr>
<tr>
<td>
<label><img src="images/stumb.png" height="40px" width="55px"></label>
<input type="checkbox" name="engine2[]" value="stumbleupon">
</td>
<td>
<label><img src="images/diig.png" height="40px" width="40px"></label>
<input type="checkbox" name="engine2[]" value="diigo">
</td>
</tr>
</table>
</div>
<!-- container ko end -->
</fieldset>
两个名称为engine1和engine2的集合。我想使用此代码使用implode将它们插入到我的数据库中。
$_POST['engine1'] = array();
$_POST['engine2'] = array();
$engine1 = implode(',', $_POST['engine1']);
$engine2 = implode(',', $_POST['engine2']);
但每次检查我的数据库表时,列都是空的。 你认为我做错了什么?请帮忙!
答案 0 :(得分:1)
您将$ _POST ['engine1']声明为空数组,如果存在则覆盖它。删除以下行:
$_POST['engine1'] = array();
$_POST['engine2'] = array();
这样$ _POST ['engine1']来自POSTED表单值。
答案 1 :(得分:1)
删除以下行:
$_POST['engine1'] = array();
$_POST['engine2'] = array();
仅使用:
$engine1 = implode(',', $_POST['engine1']);
$engine2 = implode(',', $_POST['engine2']);