dongyou5271
2016-04-20 09:39
浏览 43
已采纳

PHP- MySQL数据库插入操作不起作用[重复]

This question already has an answer here:

My php code that insert $_POST into database doesn't work.

The error = Parse error: syntax error, unexpected '). The $sql is also correct..

The Connection with Database is fine. What am I doing wrong

<?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');    
}
?>

The 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>&nbsp;</td>
            <td>
                <input type="submit" id="knop" name="knop" value="Add New Suezbox">
            </td>
        </tr>
    </table>
</form>
</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanli9591 2016-04-20 09:43
    已采纳

    Replace the line with proper line:

    if(){
    

    There is no condition added in if.

    It will always return NULL and your query will never be executed.

    Your SQL has six fields and you are binding 7 values.

    That is mismatch.

    Correct SQL to:

    $sql = "INSERT INTO workstations_nl (workstation_name, 
    workstation_user, teamviewer_id, unattended_access, suezbox_id, 
    function) VALUES (?,?,?,?,?,?)"; 
    // Observe the question marks. One is removed.
    
    点赞 打赏 评论

相关推荐 更多相似问题