$sql = "INSERT INTO newuserformtable (First Name, Last Name, Title) VALUES ('Alex', 'Picone', 'CEO')";
$stmt = sqlsrv_query( $conn, $sql, $params);
$params = array(1, "some data");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
此代码给了我这个错误
"Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] =>
[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'Name'.
[message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'Name'. ) ) "
答案 0 :(得分:1)
您需要插入这样的数据
INSERT INTO newuserformtable ([First Name], [Last Name], [Title]) VALUES ('Alex', 'Picone', 'CEO')
如果要在列中添加空格,则上面是插入查询的语法。
答案 1 :(得分:0)
在列名中添加引号,因为它在
之间有空格$sql = "INSERT INTO newuserformtable ('First Name', 'Last Name', 'Title') VALUES ('Alex', 'Picone', 'CEO')";
$stmt = sqlsrv_query( $conn, $sql, $params);
$params = array(1, "some data");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
答案 2 :(得分:0)
我认为你应该使用
$sql = "INSERT INTO newuserformtable (`First Name`, `Last Name`, `Title`) VALUES ('Alex', 'Picone', 'CEO')";