我在保存在数据库中的表单时遇到了一点问题。
基本上,我有一个带有复选框的表单,每个复选框都连接到MySQL数据库内的列,然后在检查时,按下了SubmistButton,它将从该复选框中保存值,如果没有,它将保持空。
Everyting 工作正常并保存到数据库中,但未选中的框会发出以下通知:
Undefined index: WBR in /var/www/vhosts/leadserver.be/httpdocs/LPRamen/insert.php on line 35
这是一段 HTML:
<table>
<tr>
<td><input id="vlaams-brabant" type="checkbox" name="VBR" value="Vlaams-Brabant"/> Vlaams-Brabant</td>
<td><input id="waals-brabant" type="checkbox" name="WBR" value="Waals-Brabant"/> Waals-Brabant </td>
</tr>
<tr>
<td><input id="oost-vlaanderen" type="checkbox" name="OVL" value="Oost-Vlaanderen"/> Oost-Vlaanderen </td>
<td><input id="west-vlaanderen" type="checkbox" name="WVL" value="West-Vlaanderen"/> West-Vlaanderen </td>
</tr>
等等等等。这背后的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['VBR'] = $conn->real_escape_string($_POST['VBR']);
$adds['WBR'] = $conn->real_escape_string($_POST['WBR']);
$adds['OVL'] = $conn->real_escape_string($_POST['OVL']);
$adds['WVL'] = $conn->real_escape_string($_POST['WVL']);
$adds['LIM'] = $conn->real_escape_string($_POST['LIM']);
$adds['ANT'] = $conn->real_escape_string($_POST['ANT']);
$adds['LUI'] = $conn->real_escape_string($_POST['LUI']);
$adds['HEN'] = $conn->real_escape_string($_POST['HEN']);
$adds['LUX'] = $conn->real_escape_string($_POST['LUX']);
$adds['NAM'] = $conn->real_escape_string($_POST['NAM']);
$adds['NAT'] = $conn->real_escape_string($_POST['NAT']);
$adds['INT'] = $conn->real_escape_string($_POST['INT']);
$adds['BHG'] = $conn->real_escape_string($_POST['BHG']);
$adds['leads'] = $conn->real_escape_string($_POST['leads']);
$adds['akkoord'] = $conn->real_escape_string($_POST['akkoord']);
//$adds['Regio'] = $conn->real_escape_string($_POST['Regio']);
//Regio is geen string maar een array dus kan ook niet zo gedeclareerd worden
/*$Regio = array();
$adds['Regio'] = "";
if(count($_POST['Regio']) > 0) {
foreach($_POST['Regio'] as $key=>$value)
$Regio[] = $conn->real_escape_string($value);
}
$adds['Regio'] = implode(',', $Regio);
*/
// query voor INSERT INTO
$sql = "INSERT INTO `dataramen`
(`nameCom`, `name`, `number`, `email`, `VBR`, `WBR`, `OVL`, `WVL`, `LIM`, `ANT`, `LUI`, `HEN`, `LUX`, `NAM`, `NAT`, `INT`, `BHG`, `leads`, `akkoord`)
VALUES
('". $adds['nameCom']. "', '". $adds['name']. "', '". $adds['number']. "', '". $adds['email']. "', '". $adds['VBR']. "', '". $adds['WBR']. "', '". $adds['OVL']. "', '". $adds['WVL']. "', '". $adds['LIM']. "', '". $adds['ANT']. "', '". $adds['LUI']. "', '". $adds['HEN']. "', '". $adds['LUX']. "', '". $adds['NAM']. "', '". $adds['NAT']. "', '". $adds['INT']. "', '". $adds['BHG']. "', '". $adds['leads']. "' , '". $adds['akkoord']. "')";
请记住,这些只是我的代码片段,总要发布很长时间
我知道已经有几个主题,但我已经完成了研究,但似乎没有一个解决方案有效。如果有人可以看看这个并找出问题所在,我将非常感激。
如果字段为空,我还尝试在数据库中设置一个标准值,但这不起作用。我也正确设置了数据库列上的索引,但我仍然得到相同的通知。