0

I'm getting a syntax error: Syntax error near 17:38

insert into tbl_otp('mobile', 'otp', 'exp') values (9932111111, 333333, 2019-04-09 17:38:34)
2
  • try wrapping the values with inverted commas "" Commented Apr 9, 2019 at 16:47
  • 2
    Datetime not enclosed in single quotes Commented Apr 9, 2019 at 16:47

3 Answers 3

3

Single quotes denote string literals, so you shouldn't use them for column names. You should, however, surround the date literal with quotes:

insert into
tbl_otp(mobile, otp, exp) -- no quotes
values (9932111111, 333333, '2019-04-09 17:38:34') -- quotes
Sign up to request clarification or add additional context in comments.

1 Comment

You should quote column names with backticks not just leave them open. It's a good habit.
1
insert into tbl_otp(`mobile`, `otp`, `exp`) 
values ('9932111111', '333333', '2019-04-09 17:38:34')

Need to backquote your column names and single-quote your values, though the latter is just to be safe.

5 Comments

You mean "former"
column names are not reseved words, no need for backticks
I edited to format the code with 4-space indentation, so the backticks would be more clearly visible.
@LelioFaieta Until one day they are. It doesn't hurt. Use backticks. Good habit.
I once upgraded our systems past MySQL 5.6.2, which made PARTITION a reserved word, to find that our codebase had a query without backticks around field names where one of the field names was "partition". We had to push a new build to literally everybody, for a two character fix that should never have been necessary in the first place. Wasn't nice!
0

put the date value in quotes and remove quotes from column names:

insert into tbl_otp(mobile, otp, exp) values (9932111111, 333333, '2019-04-09 17:38:34')

1 Comment

fixed the column names to remove the single quotes

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.