Solved

Checkbox problem

Posted on 2006-10-20
12
184 Views
Last Modified: 2013-12-24
Hello!

I have couple of images with checkbox. There have 5 images and user can choose his favourite image, then user press submit button and that checkbox data go to the action page. But now the problem is that action page insert all pictures to the database (not that which is user favourite image)

Here is my inset page code
<cfquery name="getdetails" datasource="#dsn#">
select imgid, picture, text
from pictures
</cfquery>
<html>
<head>
<title>pictures</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="laheta2_action.cfm" method="post">
<table width="500">
<cfloop query="getdetails">


          <td>
          <cfoutput><font face="Arial, Helvetica, sans-serif" size="2"><img src="#dir##getdetails.picture#" border=0 width=100 alt="">
            <input name="picture" type="checkbox" value="#imgid#">
            <INPUT type="hidden" name="nimi" value="#kuva#">
            <br>
         
            <br>
            </font></cfoutput> </td>
      
      
      </tr>
       <cfset tc=0>
      </cfloop>  </table>
 <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>


...and here is my action page code (where the magic happens, I want that only those pictures goes to the database which user have chosen using checkbox)

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<cfif isDefined("form.picture")>
 <cfloop list="#form.picture#" index="i">
   <cfquery name="syota" datasource="#dsn#">
INSERT INTO            kilpi      
                        (imgid, picture)
VALUES
                        ('#imgid#', '#form.picture#')
   </cfquery>
 </cfloop>
</cfif>



</body>
</html>

0
Comment
Question by:mattimeikalainen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 17774290
Change to this and see if it helps...


Change Image to this...

<img src="#dir##picture#" border=0 width=100 alt="">

Change checkbox to this....

<input name="picture" type="checkbox" value="#imgid#|#picture#">




Change if statement on action page to this...

<cfif isDefined("form.picture")>
   <cfloop list="#form.picture#" index="i">
      <cfquery name="syota" datasource="#dsn#">
         INSERT INTO kilpi (imgid, picture)
         VALUES ("#listfirst(i,'|')#", "#listlast(i,'|')#")
      </cfquery>
   </cfloop>
</cfif>
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 17774390
when you loop over a list ie:

as you have here....

 <cfloop list="#form.picture#" index="i">
   <cfquery name="syota" datasource="#dsn#">
       INSERT INTO  kilpi (imgid, picture)
       VALUES ('#imgid#', '#form.picture#')
   </cfquery>
 </cfloop>

the index "i" is the actual list item for each iteration through the loop...
so you can see why each time you looped, you weren't even referencing the list, you just had variables in there...

so lets say you have a list like so...

Try this simple example to see what I mean......

<cfset myList = "Honda, Ford, Buick, Chevy">
<cfoutput>
  <cfloop list="#myList#" index="myCar">
   #myCar#<br>
  </cfloop>
</cfoutput>

See how "myCar" is actually the item in the list? So that's why we give your check box the value "ImageId"|"Picture"

because with each one selected... you'll form a list like so...  image001|picture001,image003|picture003

then you loop over that list wit say the index of "TheItem"

which will give you each item...

1)   image001|picture001
2)   image003|picture003

then listfirst(TheItem,'|') will give you "image001"
and listlast(TheItem,'|') will give you "picture001"

it's like a list within a list...
0
 

Author Comment

by:mattimeikalainen
ID: 17775312
Sorry, that not work. It still insert all pictures to the database.
0
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 17775509
can you repost your code with the changes you made?
0
 

Author Comment

by:mattimeikalainen
ID: 17775679
this send page:

<cfloop query="getdetails">


          <td>
          <cfoutput><font face="Arial, Helvetica, sans-serif" size="2"><img src="#dir##kuva#" border=0 width=100 alt="">
            <input name="kuvat" type="checkbox" value="#imgid#|#picture#">
            <INPUT type="hidden" name="nimi" value="#picture#">


and this is action page:

<cfif isDefined("form.picture")>
   <cfloop list="#form.picture#" index="i">
      <cfquery name="syota" datasource="#dsn#">
         INSERT INTO kilpi (imgid, picture)
         VALUES ("#listfirst(i,'|')#", "#listlast(i,'|')#")
      </cfquery>
   </cfloop>
</cfif>
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 17775791
in looking at this, you changed your checkbox name to "kuvat", but you didn't change the "form.pictures" name in the action page to match that value

try this on your action page...

<cfif isDefined("form.kuvat")> <!--- this has to be the form name of your checkbox --->
   <cfloop list="#form.kuvat#" index="i"> <!--- this has to be the form name of your checkbox --->
      <cfquery name="syota" datasource="#dsn#">
         INSERT INTO kilpi (imgid, picture)
         VALUES ("#listfirst(i,'|')#", "#listlast(i,'|')#")
      </cfquery>
   </cfloop>
</cfif>
0
 

Author Comment

by:mattimeikalainen
ID: 17776220
I chance my database and cfm code little bit. Here is the new ones
 input page:
<form action="laheta2_action.cfm" method="post">
<table width="500">
<cfloop query="getdetails">


          <td>
          <cfoutput><font face="Arial, Helvetica, sans-serif" size="2"><img src="#dir##getdetails.kuva#" border=0 width=100 alt="">
            <input name="kuva" type="checkbox" value="#imgid#|#kuva#">
            <INPUT type="hidden" name="nimi" value="#kuva#">
            <br>
         
            <br>
            </font></cfoutput> </td>
      
      
      </tr>
       <cfset tc=0>
      </cfloop>

action page:

<cfif isDefined("form.kuvat")>
   <cfloop list="#form.kuvat#" index="i">
      <cfquery name="syota" datasource="#dsn#">
         INSERT INTO kilpi (tunnus, kuva)
         VALUES ('#tilausnumero#', "#listlast(i,'|')#")
      </cfquery>
   </cfloop>
</cfif>



but now i get next error message  [Microsoft][ODBC Microsoft Access Driver] Invalid bracketing of name '[kayntikortti3.jpg]'.
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 17776511
change it to this instead.... you "have" to make sure the form you're looping over in the action page has the same name as the checkbox....

<form action="laheta2_action.cfm" method="post">
<table width="500">
<cfloop query="getdetails">


         <td>
          <cfoutput><font face="Arial, Helvetica, sans-serif" size="2"><img src="#dir##getdetails.kuva#" border=0 width=100 alt="">
            <input name="kuva" type="checkbox" value="#getdetails.kuva#">
            <INPUT type="hidden" name="nimi" value="#getdetails.kuva#">
            <br>
         
            <br>
            </font></cfoutput> </td>
     
     
     </tr>
      <cfset tc=0>
     </cfloop>

action page:

<cfif isDefined("form.kuva")>
   <cfloop list="#form.kuva#" index="i">
      <cfquery name="syota" datasource="#dsn#">
         INSERT INTO kilpi (tunnus, kuva)
         VALUES ('#tilausnumero#', "#i#") <!--- also note here --->
      </cfquery>
   </cfloop>
</cfif>




I'm not sure what the variable "tilausnumero" is, but if it doesn't need to be specific to the item selected, you're fine... otherwise stick to what we did before with the "imgid"
0
 

Author Comment

by:mattimeikalainen
ID: 17779157
"tilausnumero" =(ordernumber)
is this:

<cfset theList = "1234567890">
<cfset tilausnumero = "">
<cfloop from="1" to="8" index="idx">
  <cfset tilausnumero = tilausnumero & mid(theList, randRange(1,len(theList)), 1)>
</cfloop>
0
 

Author Comment

by:mattimeikalainen
ID: 17779240
We are so close, now i change code little bit and now data goes to the database. But only and big problem is that when I choose example 3 pictures, that data goes three times in to database. Here is link to my print screen picture from my database.

http://www.realex.fi/coldfusion/database.jpg

and here is codes
send page:

<form action="laheta2_action.cfm" method="post">
<table width="500">
<cfloop query="getdetails">
          <td>
          <cfoutput><font face="Arial, Helvetica, sans-serif" size="2">
<img src="#dir##getdetails.kuva#" border=0 width=100 alt="">
<input name="kuva" type="checkbox" value="#getdetails.kuva#">
            <br>
            <br>
            </font></cfoutput> </td>      
      </tr>
       <cfset tc=0>
      </cfloop

and action page:

<cfset theList = "1234567890">
<cfset tilausnumero = "">
<cfloop from="1" to="8" index="idx">
  <cfset tilausnumero = tilausnumero & mid(theList, randRange(1,len(theList)), 1)>
</cfloop>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<cfif isDefined("form.kuva")>
   <cfloop list="#form.kuva#" index="i">
      <cfquery name="syota" datasource="#dsn#">
         INSERT INTO kilpi (tunnus, kuvat)
         VALUES ('#tilausnumero#','#form.kuva#')
      </cfquery>
   </cfloop>
</cfif>
</body>
</html>
0
 
LVL 20

Accepted Solution

by:
trailblazzyr55 earned 200 total points
ID: 17780612
change your last statement on your action page to this..... and it'll fix that problem


<cfif isDefined("form.kuva")>
   <cfloop list="#form.kuva#" index="myImg">
      <cfquery name="syota" datasource="#dsn#">
         INSERT INTO kilpi (tunnus, kuvat)
         VALUES ('#tilausnumero#','#myImg#')
      </cfquery>
   </cfloop>
</cfif>

When looping over a list like above, your use the index variable to get the item in the list to insert...

~trail
0
 

Author Comment

by:mattimeikalainen
ID: 17783455
Thank you very much!
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question