Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
bhillwig #1
updating db from dynamic form variables
I am having a hard time trying to figure out how to update my database from a
form of dynamically populated formfields. I searched around and read some
things on looping...but I think I am doing it wrong.
Here is what my form page looks like:
<cfform name="renewads" method="post" action="act_adstorenew.cfm">
<strong>Pick a date the renewed listing will run:</strong><br>
<cfinput type="text" name="DateToRun" size="20" required="yes" message="You
must enter a date listing will run">
<cfoutput query="getlistings" group="Newspaper">
<h3>#Newspaper# Listings</h3>
<cfoutput>
<br>
Current Date: #DateFormat(DateToRun, 'mm/dd/yyyy')#<br>
Renew? <input type="checkbox" name="renew" value="Yes">#Area#<br>
#Address# $#Price#<br>
#Description#
<br>
</cfoutput>
</cfoutput>
<input type="submit" value="Renew This Listing">
</cfform>
What I want to happen is... be able to pick a date and enter it in the
form...then the query spits out all the info in the database with a checkbox
named "renew" next to it. Then I want to be able to click the checkbox next to
each one I want to update...click submit....and have the date field updated in
the database for each of those listings according to what date I entered at the
beginning of the form.
I just don't know if exactly what I am trying to do is possible, and if so how
to go about doing it. Any help is greatly appreciated. Thanks.
bhillwig Guest
-
Variables not updating
I retreive some variables from PHP and display them in the movie I can only see these new variables if I empty my cache and refresh the browser.... -
Updating DB from form
My project is on MSSQL Can someone set me on the right track. I need to be able to allow users to update their profile. Is there a way to... -
Form updating keyfields
Further to my earlier post I have simplified the problem with a simple database setup which explains it more clearly I hope. Using Access 2002, I... -
Updating via Form to linked tables
I have a set of linked tables (To Oracle DB) that I need to update via a form. Up to now, I have had pretty straightforward forms that basically... -
updating fields in a form
I am trying to enter a name into a form and have an "invisible" field on the same form automatically updated. Both fields are in the same table. ... -
jdeline #2
Re: updating db from dynamic form variables
All your checkboxes have the same name and the same value when checked. You
can't tell what's what when you get to the results page. For example, if you
have ten check boxes and select four of them, your results page will see
RENEW=Yes,Yes,Yes,Yes
Try something like the code below, where each checkbox value has the ID of the
record.
<INPUT TYPE="checkbox" NAME="renew" VALUE="#getlistings.ID#">
jdeline Guest
-
bhillwig #3
Re: updating db from dynamic form variables
Thank you for the advice. I used the coding you told me:
<INPUT TYPE="checkbox" NAME="renew" VALUE="#getlistings.ID#">
When I click the check box on only one dynamic field in the form, the update
works. But if I pick multiple checkboxes it doesn't work. Don't I need some
type of loop on my update statement to insert multiple values from the dynamic
form? Here is what my update statement looks like:
<cfquery name="addinfo" datasource="#dsn#">
UPDATE Submissions
SET DateToRun = '#form.DateToRun#'
WHERE id = #form.renew#
</cfquery>
bhillwig Guest
-
Kronin555 #4
Re: updating db from dynamic form variables
Change:
WHERE id = #form.renew#
To:
WHERE id IN (#form.renew#)
When multiple renew checkboxes are checked, when you look at FORM.renew it'll contain something like:
1,34,52
Kronin555 Guest
-
bhillwig #5
Re: updating db from dynamic form variables
^^ That's what did it! Thank you both for the help!
bhillwig Guest



Reply With Quote

