Avatar of JohnMac328
JohnMac328Flag for United States of America

asked on 

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>
ColdFusion LanguageMicrosoft SQL Server

Avatar of undefined
Last Comment
JohnMac328
Avatar of _agx_
_agx_
Flag of United States of America image

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>
Avatar of JohnMac328
JohnMac328
Flag of United States of America image

ASKER

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.
Avatar of _agx_
_agx_
Flag of United States of America image

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>
Avatar of JohnMac328
JohnMac328
Flag of United States of America image

ASKER

Ok it ran but it filled the whole table with the one record I clicked on
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of JohnMac328
JohnMac328
Flag of United States of America image

ASKER

Thanks again as always agx!
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo