updating db from dynamic form variables

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default 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#&nbsp;&nbsp;$#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

  2. Similar Questions and Discussions

    1. 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....
    2. 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...
    3. 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...
    4. 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...
    5. 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. ...
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default 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

  6. #5

    Default Re: updating db from dynamic form variables

    ^^ That's what did it! Thank you both for the help!
    bhillwig Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139