php INSERT INTO语法问题[关闭]

php INSERT INTO语法问题[关闭]

问题描述:

INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, ‘Archival Information’, ‘B479’, 4321, ‘Robin’);

This works, but this does not:

INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, ‘Archival Information’, ‘B479’, 4321, ‘Robin’),
(51, ‘Information Retrieval’, ‘B431’, 4322, ‘Sheela’),
(52, ‘Information Organization’, ‘B410’, 4323, ‘Craig’),
(53, ‘Information Policy’ ‘B204’, 4324, ‘Michael’),
(54, ‘Information Management’, ‘B219’, 4331, ‘Chris’),
(55, ‘Information Security’, ‘B225’, 4332, ‘Steve’),
(56, ‘Information Technology’, ‘B435’, 4333, ‘Arthur’),
(57, ‘Information Design’, ‘B300’, 4334, ‘Amy’),
(58, ‘Health Informatics’, ‘B428’, 4330, ‘Rav’),
(59, ‘Information Ethics’, ‘B356’, 4320, ‘Simon’);

What's the problem? I've checked syntax online and this is how I've noted the proper syntax is typed out.

  INSERT INTO Departments(DepartmentID,DepartmentName,Location,Phone,Chair)
VALUES(50,'Archival 信息','B479',4321,'Robin'); 
  code>  pre> 
 
 

这有效,但这不起作用: p>

   INSERT INTO Departments(DepartmentID,DepartmentName,Location,Phone,Chair)
VALUES(50,'Archival Information','B479',4321,'Robin'),
(51,'Information Retrieval','B431  ',4322,'Sheela'),
(52,'信息组织','B410',4323,'克雷格'),
(53,'信息政策''B204',4324,'迈克尔'),  
(54,'信息管理','B219',4331,'克里斯'),
(55,'信息安全','B225',4332,'史蒂夫'),
(56,'信息技术 ','B435',4333,'亚瑟'),
(57,'信息设计','B300',4334,'艾米'),
(58,'健康信息学','B428',4330,  'Rav'),
(59,'信息伦理','B35  6',4320,'西蒙'); 
  code>  pre> 
 
 

有什么问题? 我已经在线检查了语法,这就是我注意到输入正确语法的方式。 p> div>

Your single quotes are not correct except first one

BTW your sql server is important only mssql 2008 or newer and mysql 4.1 or newer supports inserting more then one value with comma separating.

The correct sql query :

INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, 'Archival Information', 'B479', 4321, 'Robin'),
(51, 'Information Retrieval', 'B431', 4322, 'Sheela'),
(52, 'Information Organization', 'B410', 4323, 'Craig'),
(53, 'Information Policy', 'B204', 4324, 'Michael'),
(54, 'Information Management', 'B219', 4331, 'Chris'),
(55, 'Information Security', 'B225', 4332, 'Steve'),
(56, 'Information Technology', 'B435', 4333, 'Arthur'),
(57, 'Information Design', 'B300', 4334, 'Amy'),
(58, 'Health Informatics', 'B428', 4330, 'Rav'),
(59, 'Information Ethics', 'B356', 4320, 'Simon');

@exussum warn me about the mysql version so, I edited supported mysql version number 5.5 to 4.1 thank you.

INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES 
    (50, 'Archival Information', 'B479', 4321, 'Robin'),
    (51, 'Information Retrieval', 'B431', 4322, 'Sheela'),
    (52, 'Information Organization', 'B410', 4323, 'Craig'),
    (53, 'Information Policy', 'B204', 4324, 'Michael'),
    (54, 'Information Management', 'B219', 4331, 'Chris'),
    (55, 'Information Security', 'B225', 4332, 'Steve'),
    (56, 'Information Technology', 'B435', 4333, 'Arthur'),
    (57, 'Information Design', 'B300', 4334, 'Amy'),
    (58, 'Health Informatics', 'B428', 4330, 'Rav'),
    (59, 'Information Ethics', 'B356', 4320, 'Simon');

VALUES (50, 'Archival Information', 'B479', 4321, 'Robin'),
(51, ‘Information Retrieval’, ‘B431’, 4322, ‘Sheela’),

your first line used a single quote, while your second used backticks.

In MySQL the backtick is the identifier quote meaning it treats the inside as an identifier. for example a table name. a regular quote is treated as data to be inserted.

Convert line 2 on wards to use ' instead of '`'

http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

You are missing a comma on line four of values (between 'Information Policy' and 'B204'). After correcting this it works for me.