将$_POST
插入数据库的PHP代码不起作用。
错误=解析错误:语法错误,意外')。 $ sql也是 正确..
与数据库的连接很好。 我做错了什么
<?php
if(isset($_POST['knop'])){
if(){
//IN DB STEKEN
$sql = "INSERT INTO workstations_nl (workstation_name, workstation_user, teamviewer_id, unattended_access, suezbox_id, function) VALUES (?,?,?,?,?,?,?)";
$waardes = array($_POST['name'],$_POST['user'],$_POST['teamviewer'],$_POST['unattended_access'],$_POST['suezbox'],$_POST['function']);
Db::execute($sql,$waardes);
header('Location: workstations_nl.php?msg=insertok');
exit();
}
}else{
header('Location: insert_workstations_nl.php?msg=insertnietok');
}
?>
HTML
<form id="formulier" name="formulier" enctype="multipart/form-data" action="" method="post">
<table width="90%" border="0">
<tr>
<td>User: *</td>
<td>
<input type="text" id="user" name="user">
</td>
</tr>
<tr>
<td>Workstation: *</td>
<td>
<textarea id="name" name="name" placeholder="" style="width: 50%;"></textarea>
</td>
</tr>
<tr>
<td>Teamviewer: *</td>
<td><textarea id="teamviewer" name="teamviewer" placeholder="" style="width: 50%;"></textarea></td>
</tr>
<tr>
<td>Unattended Acces: *</td>
<td><textarea id="unattended_acces" name="unattended_acces" style="width: 50%;"></textarea></td>
</tr>
<tr>
<td>Suezbox: *</td>
<td><textarea id="suezbox" name="suezbox" style="width: 50%;"></textarea></td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" id="knop" name="knop" value="Add New Suezbox">
</td>
</tr>
</table>
</form>
答案 0 :(得分:0)
用适当的行替换该行:
if(){
if
中没有添加任何条件。
它将始终返回NULL,并且永远不会执行您的查询。
您的SQL有六个字段,您绑定了7个值。
那是不匹配的。
将SQL更正为:
$sql = "INSERT INTO workstations_nl (workstation_name,
workstation_user, teamviewer_id, unattended_access, suezbox_id,
function) VALUES (?,?,?,?,?,?)";
// Observe the question marks. One is removed.