LearnersPermit
Technical User
I have a form that allows users to edit an item in an inventory system. The Checkbox is a problem - they can changed it to 0 without a problem, but when they change it to a 1 it fails. No error message is displayed.
<cfparam name="form.action" default="disp">
<cfif not isdefined("form.submit")>
<cfparam name="form.itemid" default="">
<cfparam name="form.description" default="">
<cfparam name="form.enabled" default="">
</cfif>
<!--- Set a local var for the itemid --->
<cfif ISDEFINED("form.itemid") AND form.itemid GT 0>
<cfif ISDEFINED("form.btnEdit")>
<cfset locitemid='#Trim(form.btnEdit)#'>
<cfelse>
<cfset locitemid='#form.itemid#'>
</cfif>
<cfelse>
<cfset locitemid="0">
</cfif>
<cfif ISDEFINED("form.smtDelete") AND locitemid GT 0>
<!--- Delete the Record --->
<cfquery name="qrydel" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
DELETE FROM tblStores
WHERE itemid = #locitemid#
</cfquery>
<cfset locPostMessage="Item Deleted Successfully">
<cfelseif ISDEFINED("form.smtSubmit") AND locitemid GT 0>
<!--- Edit the Item --->
<cfquery name="qryupdate" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
UPDATE tblStores
SET description = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.description#">,
unit = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.unit#">,
price = <cfqueryparam cfsqltype="cf_sql_real" value="#form.price#">,
catid = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.catid#">,
supplierid = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.supplierid#">,
other = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.other#">,
enabled = <cfif form.enabled neq ""><cfqueryparam cfsqltype="cf_sql_integer" value="#form.enabled#"><cfelse>0</cfif>
WHERE itemid = #locitemid#
</cfquery>
<cfset locPostMessage="The Item was Edited">
</cfif>
<cfquery name="qrecord" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
select tblStores.itemid,tblStores.description,tblStores.unit,tblStores.price,tblStores.catid,tblStores.supplierid,tblStores.other,tblStores.enabled,tblCategory.catid,tblCategory.category,tblSupplier.suppid,tblSupplier.supplier
from tblStores,
tblCategory,
tblSupplier
where itemid = '#locitemid#'
and tblStores.catid=tblCategory.catid
and tblStores.supplierid=tblSupplier.suppid
order by description
</cfquery>
<!---Get a Category--->
<cfquery name="qryCat" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
SELECT catid,category
FROM tblCategory
ORDER BY category ASC
</cfquery>
<!---Get a Supplier--->
<cfquery name="qrySupplier" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
SELECT suppid as supplierid,supplier
FROM tblSupplier
ORDER BY supplier ASC
</cfquery>
<cfif ISDEFINED("locPostMessage")>
<cfoutput><h3>#locPostMessage#</h3></cfoutput>
</cfif>
<cfif form.action eq "disp">
<html>
<head>
<title>"Stores Catalogue"</title>
<link rel="stylesheet" href="stores.css" type="text/css">
<br />
</head>
<body>
<table>
<tr>
<td width="25%" background="#E5E5E5;"></td>
<td width="75%">
<table cellpadding="10">
<tr><th>Edit an Item</th>
</tr>
<tr>
<td>
<pre>
<form name="editTime" action="#cgi.script_name#" method="post">
<cfoutput>
Item No.:
<input type="text" name="itemid" value="#qrecord.itemid#" size="60" maxlength="255">
Description:
<input type="text" name="description" value="#qrecord.description#" size="60" maxlength="255">
Price:
<input type="text" name="price" value="#qrecord.price#" size="60" maxlength="255">
Unit:
<input type="text" name="unit" value="#qrecord.unit#" size="60" maxlength="255">
Other:
<input type="text" name="other" value="#qrecord.other#" size="60" maxlength="255">
Available:
<input type="checkbox" name="enabled" value="#qrecord.enabled#"<cfif qrecord.enabled eq "1"> checked</cfif>>
</cfoutput>
<!---Category drop down box --->
Category:
<select name="catid">
<option value="#qryCat.category#">
</option>
<cfoutput query="qryCat">
<option value="#qryCat.catid#" <cfif qrecord.catid EQ qryCat.catid> selected</cfif>>#qryCat.category#</option></cfoutput></option>
</select>
<!---Supplier drop down box --->
Service:
<select name="supplierid">
<option value="#qrySupplier.supplier#">
</option>
<cfoutput query="qrySupplier">
<option value="#qrySupplier.supplierid#" <cfif qrecord.supplierid EQ qrySupplier.supplierid> selected</cfif>>#qrySupplier.supplier#</option></cfoutput></option>
</select>
</pre>
<input type="submit" value="Submit" name="smtSubmit">
<cfif locitemid GT 0>
<input type="Submit" value="Delete" name="smtDelete">
<input type="button" value="Cancel" onclick="location.href='edit_time.cfm'">
<cfelse>
<input type="Submit" value="Delete" name="" disabled>
<input type="button" value="Cancel" disabled>
</cfif>
</form>
</td>
</tr>
</table>
</table>
</cfif>
</body>
</html>
<cfparam name="form.action" default="disp">
<cfif not isdefined("form.submit")>
<cfparam name="form.itemid" default="">
<cfparam name="form.description" default="">
<cfparam name="form.enabled" default="">
</cfif>
<!--- Set a local var for the itemid --->
<cfif ISDEFINED("form.itemid") AND form.itemid GT 0>
<cfif ISDEFINED("form.btnEdit")>
<cfset locitemid='#Trim(form.btnEdit)#'>
<cfelse>
<cfset locitemid='#form.itemid#'>
</cfif>
<cfelse>
<cfset locitemid="0">
</cfif>
<cfif ISDEFINED("form.smtDelete") AND locitemid GT 0>
<!--- Delete the Record --->
<cfquery name="qrydel" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
DELETE FROM tblStores
WHERE itemid = #locitemid#
</cfquery>
<cfset locPostMessage="Item Deleted Successfully">
<cfelseif ISDEFINED("form.smtSubmit") AND locitemid GT 0>
<!--- Edit the Item --->
<cfquery name="qryupdate" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
UPDATE tblStores
SET description = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.description#">,
unit = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.unit#">,
price = <cfqueryparam cfsqltype="cf_sql_real" value="#form.price#">,
catid = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.catid#">,
supplierid = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.supplierid#">,
other = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.other#">,
enabled = <cfif form.enabled neq ""><cfqueryparam cfsqltype="cf_sql_integer" value="#form.enabled#"><cfelse>0</cfif>
WHERE itemid = #locitemid#
</cfquery>
<cfset locPostMessage="The Item was Edited">
</cfif>
<cfquery name="qrecord" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
select tblStores.itemid,tblStores.description,tblStores.unit,tblStores.price,tblStores.catid,tblStores.supplierid,tblStores.other,tblStores.enabled,tblCategory.catid,tblCategory.category,tblSupplier.suppid,tblSupplier.supplier
from tblStores,
tblCategory,
tblSupplier
where itemid = '#locitemid#'
and tblStores.catid=tblCategory.catid
and tblStores.supplierid=tblSupplier.suppid
order by description
</cfquery>
<!---Get a Category--->
<cfquery name="qryCat" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
SELECT catid,category
FROM tblCategory
ORDER BY category ASC
</cfquery>
<!---Get a Supplier--->
<cfquery name="qrySupplier" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
SELECT suppid as supplierid,supplier
FROM tblSupplier
ORDER BY supplier ASC
</cfquery>
<cfif ISDEFINED("locPostMessage")>
<cfoutput><h3>#locPostMessage#</h3></cfoutput>
</cfif>
<cfif form.action eq "disp">
<html>
<head>
<title>"Stores Catalogue"</title>
<link rel="stylesheet" href="stores.css" type="text/css">
<br />
</head>
<body>
<table>
<tr>
<td width="25%" background="#E5E5E5;"></td>
<td width="75%">
<table cellpadding="10">
<tr><th>Edit an Item</th>
</tr>
<tr>
<td>
<pre>
<form name="editTime" action="#cgi.script_name#" method="post">
<cfoutput>
Item No.:
<input type="text" name="itemid" value="#qrecord.itemid#" size="60" maxlength="255">
Description:
<input type="text" name="description" value="#qrecord.description#" size="60" maxlength="255">
Price:
<input type="text" name="price" value="#qrecord.price#" size="60" maxlength="255">
Unit:
<input type="text" name="unit" value="#qrecord.unit#" size="60" maxlength="255">
Other:
<input type="text" name="other" value="#qrecord.other#" size="60" maxlength="255">
Available:
<input type="checkbox" name="enabled" value="#qrecord.enabled#"<cfif qrecord.enabled eq "1"> checked</cfif>>
</cfoutput>
<!---Category drop down box --->
Category:
<select name="catid">
<option value="#qryCat.category#">
</option>
<cfoutput query="qryCat">
<option value="#qryCat.catid#" <cfif qrecord.catid EQ qryCat.catid> selected</cfif>>#qryCat.category#</option></cfoutput></option>
</select>
<!---Supplier drop down box --->
Service:
<select name="supplierid">
<option value="#qrySupplier.supplier#">
</option>
<cfoutput query="qrySupplier">
<option value="#qrySupplier.supplierid#" <cfif qrecord.supplierid EQ qrySupplier.supplierid> selected</cfif>>#qrySupplier.supplier#</option></cfoutput></option>
</select>
</pre>
<input type="submit" value="Submit" name="smtSubmit">
<cfif locitemid GT 0>
<input type="Submit" value="Delete" name="smtDelete">
<input type="button" value="Cancel" onclick="location.href='edit_time.cfm'">
<cfelse>
<input type="Submit" value="Delete" name="" disabled>
<input type="button" value="Cancel" disabled>
</cfif>
</form>
</td>
</tr>
</table>
</table>
</cfif>
</body>
</html>