Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > ColdFusion

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-04-2007, 12:32 AM   PM User | #1
rice-daddy
New to the CF scene

 
Join Date: Jan 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
rice-daddy is an unknown quantity at this point
update form, check boxes

so im trying to update the database thru a from with checkboxes

i looked at tons of example code but its still not working. heres the code:

update form:

Smoking
<cfif #rsUnit.Smoking# is "yes">
<cfinput type="checkbox" name="Smoking" checked />
<cfelse>
<cfinput type="checkbox" name="Smoking" />
</cfif>

Kitchen
<cfif #rsUnit.Kitchen# is "yes">
<cfinput type="checkbox" name="Kitchen" checked />
<cfelse>
<cfinput type="checkbox" name="Kitchen" />
</cfif>

Action Page/Handler:

<cfif not IsDefined("Form.Smoking")>
<cfset form.Smoking = "No">
<cfelse>
<cfset form.Smoking = "yes">
</cfif>

<cfif not IsDefined("Form.Kitchen")>
<cfset form.Kitchen = "no">
<cfelse>
<cfset form.Kitchen = "yes">
</cfif>


<cfquery datasource = "u31db" name = "rsUpdate">
UPDATE tblRentalUnit
SET
Smoking='#form.Smoking#',
Kitchen='#form.Kitchen#'

WHERE UnitID='#form.UnitID#'
</cfquery>



It gives me a data type mismatch error. i have no idea whats going on please help
rice-daddy is offline   Reply With Quote
Old 02-11-2007, 03:24 AM   PM User | #2
JayStang
Regular Coder

 
Join Date: Jan 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
JayStang is an unknown quantity at this point
Sounds like a SQL error. What is the datatype of the "Smoking" and "Kitchen" columns? If its looking for a integer or a booleon, use 1 or 0 instead of yes, no.

Also this is just personal preference, but i prefer using one "input" for the checkbox and integrate the if statment inside it.

example:
<input type="checkbok" name="Kitchen" <cfif rsUnit.Kitchen eq 'yes'>checked</cfif> />

pound signs are not required in a cfif either.

hope that helps
JayStang is offline   Reply With Quote
Old 02-18-2007, 09:45 PM   PM User | #3
cfmatt
New Coder

 
Join Date: Feb 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
cfmatt is an unknown quantity at this point
I would re-write your code using the cfqueryparam, its always good practice to use the cfqueryparam tag.

Something like:


Code:
<cfquery datasource = "u31db" name = "rsUpdate">
UPDATE 
	tblRentalUnit
SET 
	Smoking=<cfqueryparam value="#form.Smoking#" CFSQLType="CF_SQL_INTEGER" >,
	Kitchen=<cfqueryparam value="#form.Kitchen#" CFSQLType="CF_SQL_INTEGER" >
WHERE 
	UnitID=<cfqueryparam value="#form.UnitID#" CFSQLType="CF_SQL_INTEGER" >
</cfquery>
This example assumes that your checbox values and UnitID are integers otherwise change to suit.

Also try using cfc's if you are not already using them.

hope this helps
cfmatt is offline   Reply With Quote
Old 03-02-2007, 10:09 AM   PM User | #4
pradeepk
New to the CF scene

 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
pradeepk is an unknown quantity at this point
Also can be done like this,

Smoking
<cfif #rsUnit.Smoking# is "yes">
<cfinput type="checkbox" name="Smoking" checked />
<cfelse>
<cfinput type="checkbox" name="Smoking" />
</cfif>

Kitchen
<cfif #rsUnit.Kitchen# is "yes">
<cfinput type="checkbox" name="Kitchen" checked />
<cfelse>
<cfinput type="checkbox" name="Kitchen" />
</cfif>

Action Page/Handler:

<cfif not IsDefined("Form.Smoking")>
<cfset IsSmoking= 0>
<cfelse>
<cfset IsSmoking= 1>
</cfif>

similarly for kitchen also
....
...
...




<cfquery datasource = "u31db" name = "rsUpdate">
UPDATE tblRentalUnit
SET
Smoking=#IsSmoking#,
Kitchen=#Kitchen#

WHERE UnitID=#form.UnitID#
</cfquery>
pradeepk is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:53 AM.


Advertisement
Log in to turn off these ads.