Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#1064 -You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

I'm new to PHP and MySQL and ran into a little trouble with a learning project I'm working on.

Whenever I try to create a table

CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10) NOT NULL,
type varchar(6) NOT NULL, 
notes varchar(512),
receipt int(10),
)

I get the following error message:

#1064 - 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 ') NOT NULL, type varchar(6) NOT NULL, notes varchar(512), receipt int(10), ' at line 6**

Here is some info on what I'm working with

  1. Server type: MySQL
  2. Server version: 5.5.32 - MySQL Community Server(GPL)
  3. phpMyAdmin: 4.0.4.1, latest stable version: 4.1.7

I've spent a day knocking my head against the wall over this and now I think its time to ask for help.I was wondering if anyone can tell me what I'm doing wrong?

like image 858
tsjr63 Avatar asked Feb 15 '14 13:02

tsjr63


3 Answers

Remove the comma

receipt int(10),

And also AUTO INCREMENT should be a KEY

double datatype also requires the precision of decimal places so right syntax is double(10,2)

like image 166
G one Avatar answered Nov 04 '22 03:11

G one


One obvious thing is that you will have to remove the comma here

receipt int(10),

but the actual problem is because of the line

amount double(10) NOT NULL,

change it to

amount double NOT NULL,
like image 22
Ahmed Salman Tahir Avatar answered Nov 04 '22 04:11

Ahmed Salman Tahir


In MySQL, the word 'type' is a Reserved Word.

like image 4
ak-SE Avatar answered Nov 04 '22 02:11

ak-SE