troubleshooting Question

CF - Form insert one record at a time

Avatar of JohnMac328
JohnMac328Flag for United States of America asked on
Microsoft SQL ServerColdFusion Language
6 Comments1 Solution472 ViewsLast Modified:
I am trying to get a form to insert 1 record at a time.  The form will list several records and one will be selected with a vote button.  I have tried a cfloop index but it is not working.  The error shows that I am trying to insert all the records at one time - I am only testing with two records.  Any help is appreciated.

<cfif  isDefined("FORM.submitMVP")>
 <cfloop index="aRow" from="1" to="#val(form.MVPID)#">
  <cfquery name="enterdetails" datasource="#datasource#">
    INSERT INTO leadervotes (leaderid, voteid, votedate, mvp_ast, votelevel)
    VALUES
    (
        <cfqueryparam value="#form.SessionID#" cfsqltype="cf_sql_varchar"> ,
        <cfqueryparam value="#form.MVPID#" cfsqltype="cf_sql_varchar"> ,
        <cfqueryparam value="#form.mvpdate#" cfsqltype="CF_SQL_varchar"> ,
        <cfqueryparam value="#form.mvp_ast#" cfsqltype="cf_sql_int"> ,
        <cfqueryparam value="#form.votelevelMVP#" cfsqltype="cf_sql_int">
    )
  </cfquery>
  </cfloop>



<cfform action="vote.cfm" method="post" format="html">
<tr>
      <cfinput type="hidden" name="SessionID" value="#Session.ID#">
	  <cfinput type="hidden" name="mvpdate" value="#DateFormat(DateAdd('m', -1, MyDateTime),'YYYYMMDD')#">
      <cfinput type="hidden" name="mvp_ast" value="1">
  <td align="center"><strong><cfoutput>#DateFormat(DateAdd('m', -1, MyDateTime),'mmmm')#</cfoutput></strong></td>
 <cfoutput query="getNominated">
<cfinput type="hidden" name="MVPID" value="#MVPID#">
<tr>
<td>&nbsp;#VoterFirstName#<br />&nbsp;#VoterLastName#</td>
<td width="60%"><strong>#MVPFirstName#</strong>&nbsp;<strong>#MVPLastName#&nbsp;#MVPID#</strong><br />
#mvpreason#</td>
<td>1
  <input type="radio" name="votelevelMVP" value="1" />
  &nbsp;2
  <input type="radio" name="votelevelMVP" value="2" />
  &nbsp;3
  <input type="radio" name="votelevelMVP" value="3" />&nbsp;<input type="submit" name="submitMVP" value="Vote"></td>
</tr>
<!--SEPARATOR ROW USED DIFFERENT STYLE-->
<tr>
  <td colspan="3"></td>
</tr>
</cfoutput>
  </cfform>


Here is the error screen - the numbers 485 and 510 are the MVPID numbers of the records

Error Executing Database Query.
 
 [Macromedia][SQLServer JDBC Driver][SQLServer]Conversion failed when converting the varchar value '485,510' to data type int.  
 
 The error occurred in C:\Inetpub\wwwroot\Voting\vote.cfm: line 92
 
90 :         <cfqueryparam value="#form.mvpdate#" cfsqltype="CF_SQL_varchar"> ,
91 :         <cfqueryparam value="#form.mvp_ast#" cfsqltype="cf_sql_int"> ,
92 :         <cfqueryparam value="#form.votelevelMVP#" cfsqltype="cf_sql_int">
93 :     )
94 :   </cfquery>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros