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

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.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题