On the input :   error message if there is no such id in the database to edit?  and out put comments messed up the whole

The first page (CoGetEditForm.cfm lets you input the co id
then it get to the next page for you to edit (CoEditForm.cfm). then
it lets take action and UPDATEs (CoEditAction.cfm) finally, it goes
to the colist.cfm to query results and outputs it to html format.
<td>#comm#</td>
Question is that:
1. where and what do I do to have an error message if there
is no such id in the database to edit?
2. the out put comments messed up the whole query results
when I added it to the html out put results. What can I do to clean
this up and where do I put the code?
<!-------------------------edit
page----------------------------->
<html>
<head>
<title>Main Title</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Edit a Co based on co_ID</h1>
<table>
<cfform action="CO_EditForm.cfm" method="POST">
<tr>
<td>Co_ID</td>
<td>
<cfinput type="Text"
name="Co_ID"
message="Please enter the Co_ID"
validate="integer"
required="Yes"
size="22"
maxlength="20">
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" value="GetCo">
</td>
</tr>
</cfform>
</table>
</body>
</html>
<!------------------------------------------CO_EditForm.cfm
page------------------------------------->
<cfquery name="GetCo"
datasource="#Request.MainDSN#">
SELECT
COName,
ADD,
City,
st,
zip,
comm
FROM
CO
WHERE
Co_ID = #Val(Co_ID)#
</cfquery>
<html>
<head>
<title>Main Title</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Edit a CO</h1>
<table>
<cfform action="COEditAction.cfm" method="POST">
<cfoutput>
<input type="hidden" name="COID" value="#Val(COID)#">
</cfoutput>
<tr>
<td>CO Name</td>
<td>
<cfinput type="Text"
name="COName"
value="#GetCO.COName#"
message="Please enter a name for this CO."
required="Yes"
size="40"
maxlength="40">
</td>
</tr>
<tr>
<td>ADD</td>
<td>
<cfinput type="Text"
name="ADD"
value="#GetCO.ADD#"
message="Please enter this new CO's ADD."
required="Yes"
size="32"
maxlength="30">
</td>
</tr>
<tr>
<td>City</td>
<td>
<cfinput type="Text"
name="City"
value="#GetCO.City#"
message="Please enter a city."
required="Yes"
size="22"
maxlength="20">
</td>
</tr>
<tr>
<td>st</td>
<td>
<cfinput type="Text"
name="st"
value="#GetCO.st#"
message="Please enter a st."
required="Yes"
size="3"
maxlength="2">
</td>
</tr>
<tr>
<td>ZIP Code</td>
<td>
<cfinput type="Text"
name="zip"
value="#GetCO.zip#"
message="Please enter a valid ZIP Code."
validate="zip"
required="Yes"
size="11"
maxlength="10">
</td>
</tr>
<tr>
<td>comm</td>
<td>
<textarea cols="40" rows="5"
name="comm"><cfoutput>#GetCO.comm#</cfoutput></textarea>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" value="Update Database">
</td>
</tr>
</cfform>
</table>
</body>
</html>
<cfquery name="UpdateCO"
datasource="#Request.MainDSN#">
UPDATE CO
SET
COName = '#Trim(Form.COName)#',
ADD = '#Trim(Form.ADD)#',
City = '#Trim(Form.City)#',
st = '#Trim(Form.st)#',
zip = '#Trim(Form.zip)#',
comm =
<cfif Len(Trim(Form.comm)) GT 0>
'#Trim(Form.comm)#'
<cfelse>
NULL
</cfif>
WHERE
COID = #Val(Form.COID)#
</cfquery>
<cflocation url="COList.cfm">
<cfquery name="GetCo"
datasource="#Request.MainDSN#">
SELECT
coID,
coName,
ADD,
City,
st,
zip,
comm
FROM
co
ORDER BY
coName ASC
</cfquery>
<html>
<head>
<title>title getco</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>y List</h1>
<table>
<tr>
<td><b>ID</b></td>
<td><b>Name</b></td>
<td><b>ADD</b></td>
<td><b>City</b></td>
<td><b>st</b></td>
<td><b>ZIP Code</b></td>
<td><b>comm</b></td>
<td> </td>
</tr>
<cfoutput query="GetCompanies">
<tr bgcolor="<cfif currentrow mod
2>GHOSTWHITE<cfelse>WHITE</cfif>">
<td>#coID#</td>
<td>#coName#</td>
<td>#ADD#</td>
<td>#City#</td>
<td>#st#</td>
<td>#zip#</td>
<td>#comm#</td>
<td>
<a
href="EmployeeList.cfm?coID=#coID#">Employees</a>
<a href="coAddForm.cfm">Add</a>
<a href="coEditForm.cfm?coID=#coID#">Edit</a>
<a
href="coDeleteForm.cfm?coID=#coID#">Delete</a>
</td>
</tr>
</cfoutput>
</table>
</body>
</html>
Advertisement
Reply

After your SQL SELECT on CO_EditForm.cfm, you need a
<CFIF> that checks to see if any records were retrieved. See
below.