我正在尝试制作一个在单个 SQL 记录中写入多个复选框值的表单 到目前为止我有一些代码,但我不知道我做错了什么。
这是我所拥有的:(我的表包含复选框)
<table>
<tr>
<td><input id="vlaams-brabant" type="checkbox" name="Regio[]" value="Vlaams-Brabant"/> Vlaams-Brabant</td>
<td><input id="waals-brabant" type="checkbox" name="Regio[]" value="Waals-Brabant"/> Waals-Brabant </td>
</tr>
<tr>
<td><input id="oost-vlaanderen" type="checkbox" name="Regio[]" value="Oost-Vlaanderen"/> Oost-Vlaanderen </td>
<td><input id="west-vlaanderen" type="checkbox" name="Regio[]" value="West-Vlaanderen"/> West-Vlaanderen </td>
</tr>
<tr>
<td><input id="Limburg" type="checkbox" name="Regio[]" value="Limburg"/> Limburg </td>
<td><input id="Antwerpen" type="checkbox" name="Regio[]" value="Antwerpen"/> Antwerpen</td>
</tr>
<tr>
<td><input id="Luik" type="checkbox" name="Regio[]" value="Luik"/> Luik </td>
<td><input id="Henegouwen" type="checkbox" name="Regio[]" value="Henegouwen"/> Henegouwen </td>
</tr>
<tr>
<td><input id="Luxemburg" type="checkbox" name="Regio[]" value="Luxemburg"/> Luxemburg </td>
<td><input id="Namen" type="checkbox" name="Regio[]" value="Namen"/> Namen </td>
</tr>
<tr>
<td><input id="België" type="checkbox" name="Regio[]" value="Heel België"/> Heel België </td>
<td><input id="Internationaal" type="checkbox" name="Regio[]" value="Internationaal"/> Internationaal </td>
</tr>
<tr>
<td><input id="Brussel" type="checkbox" name="Regio[]" value="Brussel Hoofdstedelijk Gewest"/> Brussel Hoofdstedelijk Gewest </td>
</tr>
</table>
这是我的 PHP 代码(请记住,这只是更大代码的一部分,我还有其他文本字段等。已经在运行):
$adds['nameCom'] = $conn->real_escape_string($_POST['nameCom']);
$adds['name'] = $conn->real_escape_string($_POST['name']);
$adds['number'] = $conn->real_escape_string($_POST['number']);
$adds['email'] = $conn->real_escape_string($_POST['email']);
$adds['activiteit'] = $conn->real_escape_string($_POST['activiteit']);
$adds['Regio'] = $conn->real_escape_string($_POST['Regio']);
// query voor INSERT INTO
$sql = "INSERT INTO `data` (`nameCom`, `name`, `number`, `email`, `activiteit`, `Regio`)
VALUES ('". $adds['nameCom']. "', '". $adds['name']. "', '". $adds['number']. "', '". $adds['email']. "', '". $adds['activiteit']. "', '" . implode(',', $adds['Regio']) ."')";
// Performs the $sql query on the server to insert the values
if ($conn->query($sql) === TRUE) {
echo 'Uw gegevens werden opgeslagen, bedankt!';
内爆给出以下错误: 警告:内爆() [function.implode]:在第 38 行的 C:\xampplite\htdocs\LPtest\insert.php 中传递的参数无效
如果有人可以帮助我了解我在这里做错了什么,将不胜感激!先感谢您!