0

Executing this query

INSERT INTO classes(  '_fkUserID',  'date',  'time' ) 
VALUES (

'1',  '2017-07-04',  '8:15'
)

gives me the following error

#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 ''_fkUserID', 'date', 'time') VALUES ('1', '2017-07-04', '8:15')' at line 1 

I'm assuming the error has something to do with parsing the underscore, but I can't manage to find a way around it.

3 Answers 3

1

Change

classes('_fkUserID', 'date', 'time') 

To

classes(`_fkUserID`,  `date`,  `time`) 

Single quotes makes the fields as strings

You don't necessarily need to add the backticks on the column names unless they are Reserved Words to the MySql. In your sql statement, date and time are reserved words, so you must use the backticks on it, which means that it would also work as:

classes(_fkUserID, `date`,  `time`) 

Backticks are Identifier Quote Characters which means that its purpose is to make MySql understand that it should identify whatever is within it as an identifier, in your case a column name.

Sign up to request clarification or add additional context in comments.

1 Comment

If single quotes turns the value into a string, what does the back tick do?
0

It is actually:

INSERT INTO classes(_fkUserID,date,time) 
VALUES (

'1',  '2017-07-04',  '8:15'
)

Comments

0

Try removing the single quotes and use back tick symbol instead (

3 Comments

If single quotes turns the value into a string, what does the back tick do?
stackoverflow.com/questions/29402361/… You could check this StackOverflow post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.