Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

One form field to update two db fields in a record at once?

Status
Not open for further replies.

mokaplanjr

Technical User
Dec 20, 2000
33
US
That is the question. Does anyone know an efficient way to get one form field to update two fields in a record at once?

I have a select list populated with from a query that pulls two bits of info from each record -- an ID number and a text label. I want the selection to write the ID number to an ID field and the Label to fill out a Label field in another table in one smooth move. Can this be done by comma delimiting the values of each option and separating them on the action page, or am I quacking when I need to cluck?
 
You can just do two inserts to put the same value in two different tables. Some databases allow you to put multiple sql statements in the same query but for the sake of simplicity, just try this:

<cfquery name=&quot;q1&quot; datasource=&quot;myDsn&quot;>
insert into table1
(field1) values ('#form.var1#')
</cfquery>

<cfquery name=&quot;q2&quot; datasource=&quot;myDsn&quot;>
insert into table2
(field2) values ('#form.var1#')
</cfquery>

Hope this helps,
GJ
 
Yeah, this should work!
Don't use those <cfinsert> and <cfupdate> tags to much.
Rather use SQL:
This should solve your prob:

<cfquery name=&quot;qName>
UPDATE TableName
SET FieldName_1 = #Form.MyFormFieldName#,
SET FieldName_2 = #Form.MyFormFieldName#
</cfquery>
 
I really appreciate the quick responses. However, I may not have been clear about what I wanted to do or I am misunderstanding your answers. If it's the latter, I blame my 4-month-old Lab puppy for waking me so often last night (he has the bladder of a horse).

Rather than data from one field update two other tables, or data from one field update two other fields in one table, I want the results of one selection from a select list to pull data from two different fields in one table, i.e., ID and Label from Table_1, and, when selected, to each update their matching fields in another table, i.e., ID and Label in Table_2.

If I am way out in left field, please feel free to say so.
 
If I understand correctly you have answered your question already in your first posting. You can dynamically place two items of information in the value of the select box on the form page and separate these with a delimiter (a comma for example).
On the action page seperate out these two items using string or list functions and write them into your database fields.

<thrud>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top