开发者

MySQL "unknown column"

开发者 https://www.devze.com 2023-03-09 04:38 出处:网络
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.

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"));
0

精彩评论

暂无评论...
验证码 换一张
取 消