首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP一直说无效的列名

PHP一直说无效的列名
EN

Stack Overflow用户
提问于 2015-09-17 18:27:06
回答 2查看 2.5K关注 0票数 0

这是我的代码:

代码语言:javascript
运行
复制
<?php $txtCommentor = $_POST['txtCommentor'] //from form?>
<?php $txtComment = $_POST['txtComment'] //from form?>
<?php $jobno = $_GET['jobno'] //from URL?>

<?php
//Query and connect
$query = "INSERT INTO delivery_comments (commentor, comment, jobno) VALUES ($txtCommentor,$txtComment, $jobno) ";?>
<?php $results = sqlsrv_query($conn, $query);?>
<?php echo $query?>
<?php
if( $results === false ) {
     die( print_r( sqlsrv_errors(), true));
}
?>

当我运行页面时,我得到以下结果:

代码语言:javascript
运行
复制
INSERT INTO delivery_comments (commentor, comment, jobno) 
VALUES (frontdesk,bvhjfhj, 85450) 

然后我得到了错误:

代码语言:javascript
运行
复制
Array ( [0] => Array ( [0] => 42S22 [SQLSTATE] => 42S22 [1] => 207 [code] => 207 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Invalid column name 'frontdesk'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Invalid column name 'frontdesk'. ) [1] => Array ( [0] => 42S22 [SQLSTATE] => 42S22 [1] => 207 [code] => 207 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Invalid column name 'bvhjfhj'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Invalid column name 'bvhjfhj'. ) )

注意,回显的insert语句是第一个。这是正确的。然后,错误的其余部分一直告诉我要插入的数据是无效的列名。这没有任何意义。该信息不应该是列名,而是插入到列中的数据。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-09-18 14:50:34

这就是我最后使用的:

代码语言:javascript
运行
复制
$query = "INSERT INTO delivery_comments (commentor, comment, jobno) VALUES ('$txtCommentor','$txtComment', '$jobno') ";
票数 -1
EN

Stack Overflow用户

发布于 2015-09-17 20:36:17

代码语言:javascript
运行
复制
<?php $txtCommentor = $_POST['txtCommentor'] //from form?>
<?php $txtComment = $_POST['txtComment'] //from form?>
<?php $jobno = $_GET['jobno'] //from URL?>

<?php
$params = array( $txtCommentor, $txtComment, $jobno);
//Query and connect
$query = "INSERT INTO delivery_comments (commentor, comment, jobno) VALUES (?,?,?) ";?>
<?php $results = sqlsrv_query($conn, $query,$params);?>

以上是您查询的净化版本。

你应该在这方面取得更大的成功

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32637505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档