0

I was about to save the data in my table but I got this error:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'div, dep, group, loc, plan, desc, fee, pname, unit, amount, amort) VALUES ('55' at line 1

Here is my code:

$sql=
"INSERT INTO account
       (accnum, mobile, status, assignee, 
          user, position, entitlement, 
          org, div, dep, group, 
          loc, plan, desc, fee, 
          pname, unit, 
          amount, amort)
VALUES
       ('$_POST[accNum]','$_POST[mobNum]','$_POST[stat]','$_POST[assignee]',
        '$_SESSION[userType]','$_SESSION[position]','$_SESSION[entitlement]',
        '$_SESSION[orga]','$_SESSION[divi]','$_SESSION[dept]','$_SESSION[group]',
        '$_SESSION[farm]','$_SESSION[planType]','$_SESSION[promo]',
        '$_SESSION[monthFee]','$_SESSION[phoneType]','$_SESSION[unit]',
        '$_SESSION[amount]','$_SESSION[amort]')"; 
Yogus
  • 2,307
  • 5
  • 20
  • 38
imlyn
  • 11
  • 1
  • 5

2 Answers2

7

Because div, group, desc are MySQL keyword.

invisal
  • 11,075
  • 4
  • 33
  • 54
5

Use backticks

$sql="INSERT INTO account(`accnum`, `mobile`, `status`, `assignee`, `user`, `position`, `ntitlement`, `org`, `div`, `dep`, `group`, `loc`, `plan`, `desc`, `fee`, `pname`, `unit`, `amount`, `amort`)
VALUES
('$_POST[accNum]','$_POST[mobNum]','$_POST[stat]','$_POST[assignee]','$_SESSION[userType]','$_SESSION[position]','$_SESSION[entitlement]','$_SESSION[orga]','$_SESSION[divi]','$_SESSION[dept]','$_SESSION[group]','$_SESSION[farm]','$_SESSION[planType]','$_SESSION[promo]','$_SESSION[monthFee]','$_SESSION[phoneType]','$_SESSION[unit]','$_SESSION[amount]','$_SESSION[amort]')";

enter image description here

Yogus
  • 2,307
  • 5
  • 20
  • 38