My database table has columns email, username and password. I'm trying to insert these test values into them, but the query seems to be interpreting the value for the test email in a strange way. What's wrong with this query?
mysql> INSERT INTO `tbl_user`
-> (`email`, `username`, `password`)
-> VALUES
-> (`test1@notanaddress.com`, `Test_User_One`, MD5(`test1`)),
-> (`test2@notanaddress.com`, `Test_User_Two`, MD5(`test2`))
-> 开发者_C百科;
ERROR 1054 (42S22): Unknown column 'test1@notanaddress.com' in 'field list'
Try using single quotes rather than backticks round the values, i.e.
mysql> INSERT INTO `tbl_user`
-> (`email`, `username`, `password`)
-> VALUES
-> ('test1@notanaddress.com', 'Test_User_One', MD5('test1')),
-> ('test2@notanaddress.com', 'Test_User_Two', MD5('test2'))
-> ;
Backticks are used to signify column names whereas single(or double) quotes will be used as a value.
You're using the wrong quotes for the values. Use simple quotes '
to indicate a char value.
Backticks delimit field names (database names, table names or column names).
Use single or double quotes to delimit strings:
INSERT INTO `tbl_user` (`email`, `username`, `password`)
VALUES ("test1@notanaddress.com", "Test_User_One", MD5("test1")),
("test2@notanaddress.com", "Test_User_Two", MD5("test2"));
精彩评论