CF - Form insert one record at a time

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>

Open in new window



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>
JohnMac328Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_Commented:
If you want each button to submit one row only, you need to generate separate <form>'s. So move the <form> tag inside the <cfoutput>.

ie

 <cfoutput query="getNominated">

     <!--- BEGIN RECORD FORM --->
       <!--- generate one form per record --->
      <cfform action="vote.cfm" method="post" format="html">
           <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">
           .... etc ....

  </cfform>
  <!--- END RECORD FORM --->

</cfoutput>
0
JohnMac328Author Commented:
Hi agx

When I do it does not see the closing tag anymore

The end tag </cfoutput> encountered on line 152 at column 3 requires a matching start tag.
0
_agx_Commented:
Sounds like maybe you didn't not remove all of the cfoutput tags inside the <form> .  Make sure you've only got one set of <cfoutput...></cfoutput> tags - and that they're outside the <form>

<cfoutput query="getNominated">

      <cfform action="vote.cfm" method="post" format="html">
          ... no cfoutput tags here
       </cfform>

</cfoutput>
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

JohnMac328Author Commented:
Ok it ran but it filled the whole table with the one record I clicked on
0
_agx_Commented:
Oh, that's probably because of the loop around the query. You need to remove it.

<cfloop index="aRow" from="1" to="#val(form.MVPID)#">
.. query
</cfloop>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JohnMac328Author Commented:
Thanks again as always agx!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.