SQL 错误:- 语句已终止
Posted
技术标签:
【中文标题】SQL 错误:- 语句已终止【英文标题】:SQL Error:- The statement has been terminated 【发布时间】:2020-07-21 19:54:51 【问题描述】:我的代码假设将数据插入到 sql server 中,但在我提交数据后却出现了该错误。 我已经用谷歌搜索了错误消息,但由于它没有太多描述我的错误,所以我找不到合适的解决方案。感谢您的帮助!
/* ------------- php functions ------------- */
function isDuplicateName( $paramId, $paramName )
$conn = new DBMsSQL();
$query = "select 1 from vacancy_master ".
"where status in (1,2) and jobtitle = ".Common::QuoteString($paramName);
if ($paramId != '0')
$query = $query." and jobrequestid != $paramId";
$conn->Query($query);
return ($conn->GetRows() > 0);
//end of function
function isDepartmentExists( $paramId )
$conn = new DBMsSQL();
$query = "select 1 from vacancy_master where jobrequestid = $paramId";
$conn->Query($query);
return ($conn->GetRows() > 0);
//end isExistanceDepartment
/* ------------- form variables ------------- */
$gotonewpage = $_REQUEST["gotonew"];
$dowhat = $_REQUEST["dowhat"];
$param = "";
$jobrequestid = $_REQUEST["jobrequestid"];
$department = $_REQUEST["department"];
$deptid = $_REQUEST["deptid"];
$requestby = $_REQUEST["requestby"];
$deptname = $_REQUEST["deptname"];
$budget = $_REQUEST["budget"];
$jobtitle = $_REQUEST["jobtitle"];
$conn = new DBMsSQL();
/* ------------- actions ------------- */
switch ($dowhat)
case "add": //insert into vacancy master table.
$pageid = PG_DEPT_MNT_NEW_MGMT; //constant from moduleconstant.php
//duplicate job name checking
if(isDuplicateName("0", $jobtitle))
$ok = "/humanresources/vacancynew.php";
MessageBox::Info(21592,$param,"",$ok);
//****************Audit Log**********************************
$action = MessageBox::LogInfo(21592,'');
Common::AuditLog($modifyid, $moduleid, $pageid,$action,CT_ERROR);
exit(1);
//end if
每次提交新记录时,序列号(jobrequestid)都会累积
$jobrequestid = Common::getSeqNum("jobrequestid");
$insert = "insert into vacancy_master (jobrequestid, requestby, department, budget, jobtitle) ".
"values ( $jobrequestid, ".Common::QuoteString($requestby).","." $department, $budget, ".Common::QuoteString($jobtitle)."); ";
Common::AuditLog($modifyid, $moduleid, $pageid, $insert, CT_DB);
$conn->Query($insert);
$msgid = 21531; $param = $jobtitle;
break;
【问题讨论】:
我强烈建议您了解参数化/准备好的语句并首先开始使用它们。你所拥有的似乎很容易被注射。 【参考方案1】:我为我的愚蠢道歉,我的表中有一些列未标记为“允许为空”,但未在我的代码中使用。 删除这些列后,我的代码可以成功运行。
【讨论】:
以上是关于SQL 错误:- 语句已终止的主要内容,如果未能解决你的问题,请参考以下文章