Hi,
I am modifying an example that came with CF6 that will update a record.
The page works fine (is able to display the records, add new records
(which appear in the queried data), delete records), with the exception
of updating data. The updated data will not update the database (MS
Access), although no errors appear and the 'success text' indicates
that it was updated.
Also, I've noticed that the <input type="reset" value="Clear Form">
button in the "Edit Item" section isn't functional. Does this depend
upon another part of the script? Thanks - Louis
Please see below:
----------------------------------------
<!---
<cfmodule template="layout.cfm" pageName="Data Maintenance Example">
<!---
If the PAGEACTION parameter exists, that means that we were
posted to this page from either the Update, Insert, or
Delete page. So take the disired action.
--->
<cfparam name="form.Item" default="">
<cfif IsDefined("PageAction")>
<cfswitch expression="#Form.PageAction#">
<cfcase value="Insert">
<!---
PAGEACTION is insert - Add the new
employee record.
--->
<!--- <cfset NewItemID = CreateUUID()> --->
<cfquery name="AddItem"
dataSource="#request.app.dsn#">
insert into tblProcardGuide (item)
values (
<cfqueryparam value="#form.Item#"
CFSQLType="CF_SQL_CHAR">,
)
</cfquery>
<!--- By cflocating away, we prevent the user
from reloading the
page and reading the user --->
<cfset msg = URLEncodedFormat("<font color=""green"">#Item#
#Allowable# has been added!</font>")>
<cflocation url="index_edit_b.cfm?msg=#msg#">
</cfcase>
<cfcase value="Update">
<cfif FORM.Item IS NOT "">
<!---
PAGEACTION is Update - Display the employee
record in a
form first. Then, after the form is submitted,
update the
record.
--->
<cfif NOT IsDefined("submitted")>
<cfquery name="TheItem"
dataSource="#request.app.dsn#">
select item, allowable from
tblProcardGuide
where item = '#Form.Item#' ORDER BY
item ASC;
</cfquery>
<cfform action="#cgi.script_name#"
method="Post"
name="UpdateItemForm">
<input type="hidden" name="PageAction"
value="Update">
<input type="hidden" name="Item"
value="<cfoutput>#Form.Item#</cfoutput>">
<b class="text">Edit Item</b>
<br><br>
<table>
<tr>
<td>Item</td>
<td>
<cfinput type="Text"
name="Item"
value="#TheItem.item#"
message="Please
enter your Item..."
required="Yes">
</td>
</tr>
</table>
<input type="submit" value="Update
Item" name="submitted">
<input type="reset" value="Clear Form">
<input type="button" value="Cancel"
onClick="javascript:do***ent.location='index_edit_b.cfm';">
</cfform>
<hr>
<cfelse>
<cfquery name="UpdateItem"
dataSource="#request.app.dsn#">
update tblProcardGuide
set item = <cfqueryparam
value="#form.Item#"
CFSQLType="CF_SQL_CHAR">
where item = '#Form.Item#'; <!--- --->
</cfquery>
<!--- By cflocating away, we prevent
the user from reloading the
page and reediting the user --->
<cfset msg = URLEncodedFormat("<font
color=""green"">#Item# has been updated!</font>")>
<cflocation url="index_edit_b.cfm?msg=#msg#">
</cfif>
</cfif>
</cfcase>
<cfcase value="Delete">
<cfif FORM.Item IS NOT "">
<!---
PAGEACTION is Delete - remove the
employee record.
--->
<cfquery name="DeleteItem"
dataSource="#request.app.dsn#">
delete from tblProcardGuide
where Item = '#Form.Item#'
</cfquery>
<!--- No need to cflocate here - doesn't matter
if user redeletes
--->
<p><font
color="Green"><cfoutput>#Item#</cfoutput> has been
deleted!</font>
</p>
</cfif>
</cfcase>
</cfswitch>
</cfif>
<!--- If we have a status msg, display it --->
<cfif isDefined("url.msg")>
<cfoutput>
<p>
#url.msg#
</p>
</cfoutput>
</cfif>
<p>
<b>Current Items</b> (Click a name and then click Edit or Delete.)
</p>
<cfquery name="AllItems" dataSource="#request.app.dsn#">
select item from tblProcardGuide
order by item
</cfquery>
<form action="<cfoutput>#cgi.script_name#</cfoutput>" method="post"
name="CurrentItemForm">
<select name="Item" size="10">
<cfoutput query="AllItems">
<option value="#Item#">#lcase(item)#
</cfoutput>
</select>
<!---
JavaScript is used to set a hidden form field. This tells our
form
handling
code what is going on, in other words, are we updating or
deleting.
--->
<p>
<input type="Button" value=" Edit "
onClick="Javascript:do***ent.CurrentItemForm.PageAction.value='Update';do***ent.CurrentItemForm.submit();">
<input type="Button" value=" Delete "
onClick="Javascript:do***ent.CurrentItemForm.PageAction.value='Delete';do***ent.CurrentItemForm.submit();">
<input type="hidden" name="PageAction">
</p>
</form>
<hr>
<cfform action="#cgi.script_name#" method="Post" name="NewItemForm">
<input type="HIDDEN" name="PageAction" value="Insert">
<p>
<b>Add New Item</b>
</p>
<table>
<tr>
<td>Item</td>
<td><cfinput type="Text" name="Item" message="Please enter your
item..." required="Yes"></td>
</tr>
</table>
<p>
<input type="submit" value=" Add Item ">
<input type="reset" value="Clear Form">
<br />
<a href="results.cfm">results.cfm</a>
<br />
<a href="results_5_2_col_test_b.cfm">2 Column Results</a>
</p>
</cfform>
</cfmodule>


|