1

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>
Azzabi Haythem
  • 2,318
  • 7
  • 26
  • 32
Giel Evens
  • 61
  • 1
  • 10

1 Answers1

0

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.
Pupil
  • 23,834
  • 6
  • 44
  • 66