Skip to main content
Inspiring
July 17, 2008
Answered

Error Executing Database Query

  • July 17, 2008
  • 1 reply
  • 709 views
Hello,

I'm getting an "Error Executing Database Query" error when I try to submit a small form I created. Any help I can get would be greatly appreciated.


Here is the CFM code on the form page:

<cfquery name="rsGoldStar" datasource="HRTraining">
SELECT *
FROM dbo.tblEmployees
WHERE Active = 1
ORDER BY LastName ASC</cfquery>
.
.
.
Here is the form code on the form page:

<form action="thanksGS.cfm" id="form1" name="form1" method="POST">
<h3>

</h3>
<table width="68%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="100%"><h2><strong>Referred by: </strong></h2></td>
</tr>
<tr>
<td><select name="EmployeeID">
<cfoutput query="rsGoldStar">
<option value="#rsGoldStar.EmployeeID#">#rsGoldStar.LastName#, #rsGoldStar.FirstName#</option>
</cfoutput>
</select>
<strong><span class="style3 style2">(Required)</span></strong></td>
</tr>
</table>
<table width="518" border="0">
<tr>
<td width="177"><h2>Date:</h2></td>
<td width="331"><input name="GoldCardDate" type="text" id="GoldCardDate" size="8" maxlength="8" /></td>
</tr>
<tr>
<td><h2>Applicant Name: </h2></td>
<td><input name="ApplicantName" type="text" id="ApplicantName" size="40" maxlength="50" /></td>
</tr>
<tr>
<td><h2>Position Applying For: </h2></td>
<td><input name="PositionApplyingFor" type="text" id="PositionApplyingFor" size="50" maxlength="75" /></td>
</tr>
</table>
<h2> </h2>
<p><input type="submit" name="Submit" value="submit" />
<label>
<input name="Reset" type="reset" id="Reset" value="Reset" />
</label>
<label></label>
</p>
</form>

________________________

Now here is the action page CFM code:


<cftry>
<cfquery name="insertRow" datasource="HRTraining">
INSERT INTO tblGoldCards (EmployeeID, GoldCardDate, ApplicantName, PositionApplyingFor)
VALUES (<cfqueryparam value = "#form.EmployeeID#" cfsqltype="cf_sql_integer" maxlength="4">, <cfqueryparam value="#form.GoldCardDate#" cfsqltype="cf_sql_date" maxlength="8">, <cfqueryparam value="#form.ApplicantName#" cfsqltype="cf_sql_varchar" maxlength="50">, <cfqueryparam value="#form.PositionApplyingFor#" cfsqltype="cf_sql_varchar" maxlength="75">)
</cfquery>


<!--- If you sign up for a twice ERROR--->
<cfcatch type="database">
<cfif cfcatch.Message CONTAINS " ">
</cfif>
<cfrethrow />
<cfabort>
</cfcatch>
</cftry>


Thank you in advance.
    This topic has been closed for replies.
    Correct answer 2Goode
    I figured out the problem.
    I increased the maxlength from 8 to 10.
    <cfqueryparam value="#form.GoldCardDate#" cfsqltype="cf_sql_date" maxlength= "10">

    Now it works. Thanks for your help.

    1 reply

    Inspiring
    July 17, 2008
    Probably has something to to with the fact that you are not validating your date field.
    2GoodeAuthor
    Inspiring
    July 17, 2008
    Dumb question but how do I validate the date field?
    2GoodeAuthor
    Inspiring
    July 17, 2008
    I figured out the problem.
    I increased the maxlength from 8 to 10.
    <cfqueryparam value="#form.GoldCardDate#" cfsqltype="cf_sql_date" maxlength= "10">

    Now it works. Thanks for your help.