Skip to main content
Inspiring
April 1, 2008
Question

I'm sure there's a Loop solution to my update problem

  • April 1, 2008
  • 9 replies
  • 505 views
I want to update an access db with multiple records. They are property pictures. They may have the same listnumber, but all have a different ID#. There are not always a set amount of pics... may be 5 or 7 or 10, etc..

The DB fields are id, filedata (actual .jpg filename), picturename, listnumber

I am trying to add names to all pictures at once instead of one at a time. Below is the code I have... it is only updating one record at a time.

Data entry page: (output query: lookup grabs the pictures witha a specific listnumber ie:1950)

<cfoutput query="lookup">
<form enctype="multipart/form-data" action="title_picture_action.cfm?id=#listnumber#" method="POST">
<input type="hidden" name="id" value="#id#">
<input type="hidden" name="listnumber" value="#listnumber#">

<table border="0" width="500" cellpadding="10" cellspacing="0">
<tr>
<td><img src="images/uploads/#filedata#" width="100"></td>
<td><input type="text" maxlength="50" size="20" name="picturename" value="#picturename#"></td>
<!--- <td align="center"><input type="submit" value="Submit"></td> --->

<hr color="00704a" style="height = 1px">
</tr>
</cfoutput>
<tr><td><input type="submit" value="Submit"></form></td></tr>
<table>

Processing page:

<cfquery name="titlepicture" datasource="#dsn#">
UPDATE uploads SET
picturename = '#form.picturename#'
WHERE id = #form.id#
</cfquery>

<cflocation url="index.cfm

Any help will be GREATLY appreciated! Thx in advance.
    This topic has been closed for replies.

    9 replies

    Inspiring
    April 3, 2008
    Try something like this on your form page.
    cfquery name="thequery"
    select id, picturename
    from your table

    cfform
    cfloop query="thequery"
    cfinput name="picturename_#id#"

    Then on your action page you can use the name of the form field to marry it up to the proper record.
    Inspiring
    April 3, 2008
    Try something like this on your form page.
    cfquery name="thequery"
    select id, picturename
    from your table

    cfform
    cfloop query="thequery"
    cfinput name="picturename_#id#"

    Then on your action page you can use the name of the form field to marry it up to the proper record.
    Inspiring
    April 2, 2008
    What type of input is picturename on your form?
    Inspiring
    April 2, 2008
    picturename is text (from access db same name)
    Listnumber is a number (4digits)
    ID is and auto number from access (primary key)
    filedata is text (it is the actual file name ex: 1960_ext.jpg)
    Inspiring
    April 2, 2008
    *** NOTE***

    I guess the issue is that ALL THE FORM FIELDS are called form.picturename. But I want each one with a DIFFERENT ID to have a DIFFERENT picturename applied to it. Does that help?

    It's Multiple formfields with the same form field name, but I want it to loop thru (or however I need to do it) so it see: Yes this is the same form field name, but the ID is different, therfore...... THAT is what Im having the problem with.
    Inspiring
    April 2, 2008
    In my original post it is set up that way, but only 1 of the records updates. On my form page I get a list of multiple images with a form field next to them. It is only updating one field.
    Inspiring
    April 2, 2008
    without knowing your table and field names, I can offer a generic suggestion.

    for adding records.
    insert into sometable
    select stuff
    from some_other_table
    where listnumber = whatever.

    for updating.
    update sometable
    set somefield = somevalue
    where listnumber = whatever

    You don't need a loop.
    April 2, 2008
    My first read (5 seconds, too short time), on second read, try CFGRID or the type...
    Inspiring
    April 2, 2008
    My problem is NOT on the first page. In it , with the lookup query, I pull the image (filedatda) from the db and place a form field next to it - where I can add a name of the pic, ie: picturname

    My problem IS on the processing page. (the second area of code above) When I pass the picturename it only adds ONE to the database. I need it to loop throught and add each pictuname to each image (filedata in db) These would all have the same listnumber but different ID.
    Inspiring
    April 1, 2008
    I dont understand what you mean. I can pull the listnumber out of the url... I was just passing it thru there, but that wont fix my issue will it?
    April 1, 2008
    Wait a sec.
    "<cfoutput query="lookup">
    <form enctype="multipart/form-data" action="title_picture_action.cfm?id=#listnumber#" method="POST">
    ...
    "
    look like you'll have multiple forms and each form ...