Skip to main content
Participant
October 31, 2020
Question

Suddenly can't populate a field with CF INSERT

  • October 31, 2020
  • 1 reply
  • 186 views

I have an INSERT command in a CF script to add a record to a data table. There are four fields I am populating. Fields three and four are being populated with the same data. Here’s the code:

        INSERT INTO tblPQMS_Requests

          (

          PQMSReq_By,

          PQMSReq_Status,

          PQMS_Proj,

          ERP_PQMS_Proj

          )

        VALUES

          (

          'LibMgr',

          '1',

          '#htmlEditFormat(projectno)#',

          '#htmlEditFormat(projectno)#'  <!--- Suddenly can't get this field filled! --->

          )

You see my comment on the last line. I can’t get projectno into ERP_PQMS_Proj. In fact, I can’t get ANYTHING into the field named ERP_PQMS_Proj, even if I just try to stick a bit of text into this text field.

 

Furthermore, the procedure worked until a few days ago!

 

I have never experienced this "locked-field syndrome" before and have spent hours trying to figure out what is going on. Any ideas? Thanks!

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
November 3, 2020

Two remarks.

1) HtmlEditFormat has been deprecated. Assuming you have a recent version of ColdFusion, replace it with EncodeForHTML.

2) Use parameter-binding (cfsqltype). If your query fails because of parameter type, then ColdFusion will likely tell you so.

Try something like:

<cfscript>
sqlString="
INSERT INTO tblPQMS_Requests
  (
  PQMSReq_By,
  PQMSReq_Status,
  PQMS_Proj,
  ERP_PQMS_Proj
  )
VALUES
  (
  :PQMSReqBy,
  :PQMSReqStatus,
  :PQMSProj,
  :ERPPQMSProj
  )";

// Bind the parameter types
sqlParameters={
	PQMSReqBy={value='LibMgr', cfsqltype="varchar"},
	PQMSReqStatus={value='1', cfsqltype="varchar"},
	PQMSProj={value='#encodeForHTML(projectno)#' , cfsqltype="varchar"},
	ERPPQMSProj={value='#encodeForHTML(projectno)#' , cfsqltype="varchar"}
}

// insert-query
queryExecute(sqlString, sqlParameters, {datasource="yourDSN"});
</cfscript>

 

 

dcoppsAuthor
Participant
November 3, 2020
Thanks! I'll give it a try.

-Dale