Skip to main content
Participant
January 26, 2022
Answered

populating check boxes from database then taking to landing page and inserting into another table

  • January 26, 2022
  • 1 reply
  • 199 views

Hi,

I'm really struggling with this. I'm trying to populate the check boxes from the database, which I've managed. It then goes through to the landing page, but it takes the literal variable name with it instead of the value. 

 

This is the code on first page:

 

<cfquery name="fromTools" datasource="cfook">

    SELECT tools FROM toolsin WHERE custid = #custid#
</cfquery>
 
    <cfform action="landing.cfml" method="post">
<!--- Check box. --->
<cfloop query="fromTools">

    <input type="checkbox" name="myDataList" value="#fromTools.tools#" ><cfoutput>#fromTools.tools#</cfoutput> <br />

</cfloop>
 
<cfinput type="Submit" name="SubmitForm" value="Submit">
</cfform>
This names the checkboxes with the values from the tools column from the database. But then it goes to page 2:
<cfquery name="toolsin" datasource="cfook">
    INSERT INTO toolsout VALUES("1234", <cfqueryparam value="#form.myDataList#">, CURRENT_TIMESTAMP)
</cfquery>

<cfdump var = #Form.myDataList#>
 
The problem is that #Form.myDataList# gives the value #fromTools.tools# instead of the value retrieved from the database. But the checkbox on page 1 does have the correct value printed next to it from the cfoutput  #fromTools.tools# ... but it's taking that literal variable name instead of its value through to the next page. Any ideas?
 
Thanks in advance
 
I'm really new to coldfusion.
    This topic has been closed for replies.
    Correct answer LinuxLen

    Thanks for your reply. I solved it, it needed the value of #fromTools.tools# wrapping in a cfoutput tag to make it carry through as the variable value rather than face value of the variable name. So it's:

     

    <input type="checkbox" name="myDataList" value=<cfoutput>#fromTools.tools#</cfoutput> ><cfoutput>#fromTools.tools#</cfoutput> <br />

     

    Thanks so much for your time!

    1 reply

    BKBK
    Community Expert
    Community Expert
    January 26, 2022

    Likely cause of problem: the following line is just text

    <input type="checkbox" name="myDataList" value="#fromTools.tools#" >

     

    Hence, 2 possible solutions:

    <cfoutput><input type="checkbox" name="myDataList" value="#fromTools.tools#" >#fromTools.tools#</cfoutput> <br />

    or

     <cfinput type="checkbox" name="myDataList" value="#fromTools.tools#" ><cfoutput>#fromTools.tools#</cfoutput> <br />

     

    LinuxLenAuthorCorrect answer
    Participant
    January 27, 2022

    Thanks for your reply. I solved it, it needed the value of #fromTools.tools# wrapping in a cfoutput tag to make it carry through as the variable value rather than face value of the variable name. So it's:

     

    <input type="checkbox" name="myDataList" value=<cfoutput>#fromTools.tools#</cfoutput> ><cfoutput>#fromTools.tools#</cfoutput> <br />

     

    Thanks so much for your time!

    BKBK
    Community Expert
    Community Expert
    January 27, 2022

    Glad to hear. If you take another look, you will see that that is basically the first possibility I suggested.

     

    You should consider using one set of <cfoutput> tags, instead of two. It is best-practice from the DRY point of view, and is more efficient.