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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form problem

Status
Not open for further replies.

izachar

Technical User
Oct 7, 2000
84
CA
I have a form that has only one line but it is a <cfoutput> tag so it really generates as many rows as the criteria sets. The problem is that when I update the form it updates only one line not every record.

This is the section in the form:

<cfoutput group=&quot;de_occupant_name&quot; query=&quot;list&quot;>

<tr>
<td width=&quot;89&quot;>
<div align=&quot;center&quot;>
<input type=&quot;Text&quot; name=&quot;unit_number&quot;
value=&quot;#de_unit_number#&quot; size=&quot;10&quot;>
</div>
</td>
<td width=&quot;303&quot;>
<input type=&quot;text&quot; name=&quot;tenant_name&quot; width=&quot;35&quot;
value=&quot;#de_occupant_name#&quot; size=&quot;45&quot;>
</td>
<td width=&quot;94&quot;>
<div align=&quot;center&quot;>
<input type=&quot;Checkbox&quot; name=&quot;vacancy&quot;
value=&quot;checkbox&quot; <cfif de_vacant_indicator
eq &quot;V&quot;>checked</cfif>>
</div>
</td>

This is the page it goes to after submition:

<cfquery datasource=#datasource# username=#username# password=#password#>
update vacancy set
de_unit_number='#unit_number#',
de_occupant_name='#tenant_name#',
de_vacant_indicator='#vacant#'
where de_property_number=#de_property_number#

</cfquery>

</cfoutput>


</tr>
</cfoutput>
 
i see two problems here.

1. you have got a form that has got the various elements in it. none of the elements have a unique identifier. take unit_number for example. if you have got 5 records output on the page you are going to have 5 form elements called unit_number. you are not going to be able to identify one specific element on the page to be able to do your update. Suggest putting your primary key value after each of the form names like this:

<input type=&quot;Text&quot; name=&quot;unit_number#Primary_Key_Value#&quot; value=&quot;#de_unit_number#&quot; size=&quot;10&quot;>

do this for all of your elements on the page.

2. on your update page you are only sayng to look for one element. you will need to loop over the recordset that you used to create the page in the first place.

something like this:


<cfloop query=&quot;list&quot;>

<cfquery datasource=#datasource# username=#username# password=#password#>
update vacancy set
de_unit_number='#unit_number#',
de_occupant_name='#tenant_name#',
de_vacant_indicator='#vacant#'
where de_property_number=#de_property_number#

</cfquery>
</cfloop>
that should sort your problem
hope this helps !
 
I am runing into a problem on he update page where the unit number realy is not the unit number anymore since it has the key attached to it. how do I transfer that.
 
I am runing into a problem on he update page where the unit number realy is not the unit number anymore since it has the key attached to it. how do I transfer that.
 
sorry forgot to put a bit of code onto the page:

<cfloop query=&quot;list&quot;>
<CFSET unit_num = Evaluate(&quot;Form.#Unit_Number##List.PrimaryKeyValue#&quot;)>

<CFSET occupant_name = Evaluate(&quot;Form.#tenant_name##List.PrimaryKeyValue#&quot;)>

<CFSET vacantind = Evaluate(&quot;Form.#vacant##List.PrimaryKeyValue#&quot;)>

<cfquery datasource=#datasource# username=#username# password=#password#>
update vacancy set
de_unit_number='#unit_num#',
de_occupant_name='#occupant_name#',
de_vacant_indicator='#vacantind#'
where de_property_number=#de_property_number#

</cfquery>
</cfloop>

this should work, although using the evaluate function will slow down the processing of the page somewhat
 
I think I am almost thre but I am getting an error on the Evaluate. I am sending the full page so you can see maybe the error is somewhere else. I decided to update only one field, the vacancy

Thanks for the help.

<cfquery datasource=#datasource# username=#username# password=#password# name=&quot;list&quot;>
select * from vacancy
</cfquery>

<html>
<head>
<title>Untitled</title>
</head>

<body>


<cfloop query=&quot;list&quot;>

<CFSET vacantind = Evaluate(&quot;Form.#vacancy##de_id#&quot;)>

<cfif vacantid eq &quot;checked&quot;>
<cfset vacant=&quot;v&quot;>
<cfelse>
<cfset vacant=&quot;O&quot;>
</cfif>

<cfquery datasource=#datasource# username=#username# password=#password#>
update vacancy set
de_unit_number='#unit_number#',
de_occupant_name='#tenant_name#',
de_vacant_indicator='#vacant#'
where de_property_number=#de_property_number#

</cfquery>
</cfloop>
....

thanks
 
what is the error that Evaluate is returning ?

as it looks alright!

i assume that the variables vacancy and de_id are coming from your database !
 
vacancy is coming from the form and de_id is my primary key

An error occurred while evaluating the expression:
vacantind = Evaluate(&quot;Form.#vacancy##de_id#&quot;)
Error near line 20, column 7.
Error resolving parameter VACANCY

I checked the spelling in the form and it is
name=&quot;vacancy#de_id#&quot;
 

If the field on the form is named &quot;vacancy#de_id#&quot;, then you'll want they same name in the evaluate:

Code:
<CFSET vacantind = Evaluate(&quot;Form.vacancy#de_id#&quot;)>
 
still getting this on the result.

Error Diagnostic Information

An error occurred while evaluating the expression:
vacantid = Evaluate(&quot;form.vacancy#de_id#&quot;)
Error near line 21, column 7.
----------------------------------------
An error has occurred while processing the expression:
form.vacancy2
Error near line 1, column 1.
----------------------------------------
Error resolving parameter FORM.VACANCY2

I guess I do not know what to expect from the evaluate tag.

 
right i see what ur trying to do now.

what its saying is that there was no variable called Form.Vacancy2 passed from the form. what you will need to do is to check that the parameter exists first. a checkbox will only be passed if it is checked on the form.

so use the isDefined() function like so:

<CFSET formElement = &quot;Form.Vacancy#de_id#&quot;>
<CFIF isDefined('formElement') IS &quot;Yes&quot;>
<cfset vacant=&quot;v&quot;>
<CFELSE>
<cfset vacant=&quot;O&quot;>
</CFIF>

<cfquery datasource=#datasource# username=#username# password=#password#>
update vacancy set
de_unit_number='#unit_number#',
de_occupant_name='#tenant_name#',
de_vacant_indicator='#vacant#'
where de_property_number=#de_property_number#

</cfquery>
 
it seems like it solved the problem but I took out the evaluate and now when I go back to the form all the checkboxes are checked.
 
the problem is now
<CFSET formElement = &quot;Form.Vacancy#de_id#&quot;>
because it is creating a string variable not from the submited form.
So all the items are getting checked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top