Mysql syntax error when adding to columns

Mysql syntax error when adding to columns
0

#1

I’m trying to add insert information into a table I made but I’m getting an error. I don’t see what I’m doing wrong here though, but I’m also not sure how to read the error message.

mysql> describe message;
+-----------+------------+------+-----+---------+----------------+
| Field     | Type       | Null | Key | Default | Extra          |
+-----------+------------+------+-----+---------+----------------+
| id        | int(11)    | NO   | PRI | NULL    | auto_increment |
| whenAdded | datetime   | YES  |     | NULL    |                |
| comment   | text       | YES  |     | NULL    |                |
| deleted   | tinyint(1) | YES  |     | 0       |                |
+-----------+------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> INSERT INTO 'message' ('id','whenAdded','comment','deleted') VALUES (NULL,'2018-07-26 07:01:30', 'hello test hello lorem ipsem amut livi', FALSE);
ERROR 1064 (42000): 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 ''message' ('id','whenAdded','comment','deleted') VALUES (NULL,'2018-07-26 07:01:' at line 1

The problem is at line 1. Is this the id row or the whenAdded row? I’m not sure what I should change about them to make the error go away and would appreciate help with this.


#2

Your id field under the Null column says NO, but you are attempting to insert the value NULL into that field. That is not causing your issue, but it could once you fix the syntax error.

I believe the syntax error is that you wrapped single quotes around message .


#3

If your table or column names have spaces in them (or if they happen to be a reserved keyword), you need to surround them with backticks, not single quotes. Since your table and field names don’t have any spaces, you don’t need this at all; just write your table and field names without any enclosing characters.


#4

I removed the quotes around message but I’m still getting the same error.

INSERT INTO message ('id','whenAdded','comment','deleted') VALUES (NULL,'2018-07-26 07:01:30', 'hello test hello lorem ipsem amut livi', FALSE);

What should I add besides NULL? According to answers I see on stackoverflow I’m supposed to add null for my id to auto increment. Is this wrong?


#5

thanks, that was my problem.


#6

You also should not be putting single quotes around the field names as @pablopaul pointed out.

INSERT INTO message ('id','whenAdded','comment','deleted')