-2

I am trying to create my first database. I mainly used this tutorial to have my database up and connected, however, I am having some problems inserting the data from the form into the database. I know the db is connected as I can retrieve the data data back from the db to the php but not in other way round.

I tried searching, but it seems that the problem is too unique for me to generalize from the past issues already solved.

I have this error whenever I finish up the forum:

Parse error: syntax error, unexpected 'VALUES' (T_STRING) in D:\xampp\htdocs\softwarefirm\create.php on line 20

The code for the create file is:

<?php
    include 'include/connection.php';

    $name = $_POST['inputFirstName'];
    $email = $_POST['inputEmail'];
    $pnum = $_POST['inputPhoneNumber'];
    $hdate = $_POST['HireDate'];
    $jtitle = $_POST['JobTitle'];
    $salary = $_POST['Salary'];
    $manid = $_POST['ManagerID'];
    $depid = $_POST['DepartmentID'];

    if(!$_POST['submit']) {

        echo "please fill out the form";
        header('Location: index.php');
    } else {

        mysql_query("INSERT INTO employee (`EID`, `FirstName`, `Email`, `PhoneNumber`, `HireDate`, `JobTitle`, `Salary`, `ManagerID`, `DepartmentID`")
            VALUES(NULL, '$name', '$email', '$pnum', '$hdate', '$jtitle', '$salary', '$manid','$depid')") or die(mysql_error());
echo "User has been added";
header ('Location: index.php');
    }

    ?>
Cleb
  • 25,102
  • 20
  • 116
  • 151
Adnan Ahmed
  • 1
  • 1
  • 1
  • you have to fully encolse ` mysql_query("INSERT INTO employee (`EID`, `FirstName`, `Email`, `PhoneNumber`, `HireDate`, `JobTitle`, `Salary`, `ManagerID`, `DepartmentID` **"** ) VALUES(NULL, '$name', '$email', '$pnum', '$hdate', '$jtitle', '$salary', '$manid','$depid')"` as a string. - well – Bagus Tesa Nov 29 '15 at 17:48
  • 2
    Start by removing the `"` just before VALUES in your mysql statement – Mike -- No longer here Nov 29 '15 at 17:48
  • Also consider in changing your mysql_* functions by mysqli_* or PDO since mysql_* are deprecated! – Jorge Campos Nov 29 '15 at 17:51

1 Answers1

0

Here's the error:

mysql_query("INSERT INTO employee (`EID`, `FirstName`, `Email`, `PhoneNumber`, `HireDate`, `JobTitle`, `Salary`, `ManagerID`, `DepartmentID`")
        VALUES(NULL, '$name', '$email', '$pnum', '$hdate', '$jtitle', '$salary', '$manid','$depid')")

Remove the second double-quotes from the mysql_query-line. The line should end with:

`DepartmentID`)
Thomas Landauer
  • 7,857
  • 10
  • 47
  • 99
  • Thanks a lot everyone. I figured this out only moments after posting this. I have no idea why it took me so long to figure it out. – Adnan Ahmed Nov 30 '15 at 18:26