Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / March 2006



Tip: Looking for answers? Try searching our database.

Updating Database

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WOLFcfm - 29 Mar 2006 23:32 GMT
Hi,
I hope someone could help me because I have no clue how to fix this problem
and I'm in need of some assistance.
Heres the situation, I have a form and in the form i have checkbox and
basically the way I have it set up on my web page is I will search for
something in the database and whether its a yes or no (1 or 0, true or false)
in the database the checkbox on the web page will either be checked or
unchecked. I do this like this:

<form name="whatever" method="post">   
     My Checkbox:<br>
     <cfoutput query="myqueryname">
          <cfif myqueryname.something is 1>
               <input name="checkbox" type="checkbox" value="checkbox" checked>
          <cfelse>
               <input name="checkbox" type="checkbox" value="checkbox">
          </cfif>
     </cfoutput>
     <input type="submit" name="submit" value="Update">
</form>

The purpose of the web page is to be able to check and uncheck the checkbox
and update the changes in the database through the web page. However, my code
is not working because when I attempt to do this I get this error:
Element CHECKBOX is undefined in FORM.

and it points to this part of my code:

<cfquery name="aqueryname" datasource="thesource">
update thetable
set thefield='#form.checkbox#'
where name='thename'
</cfquery>

I'm not sure if I provided enough information but any type of help will be
much appreciated.
Thank you.
JMGibson3 - 29 Mar 2006 23:42 GMT
Checkboxes in Forms work weird compared to all other controls.  Rather than
returning a variable, they either return one if checked or don't return it at
all when blank.  So <cfif Not IsDefined(Form.myCheckBox)>  is equivalent to
unchecked.  Then if your actually using a Boolean in the database (or the
infamous Yes/No in Access) you get to play around converting the conditions to
their database values.  If you have any choice in the matter, change your DB
column to text, one character, and use Y's or N's.  Much easier to view when
using utilities also.
Dan Bracuk - 30 Mar 2006 04:15 GMT
Another approach is, on your form, do this;
<input type = "hidden" name="abc" value = "N">
<input type = "checkbox" name = "abc" value = "Y">

and you will always have ListLast(form.abc) to work with
WOLFcfm - 30 Mar 2006 08:15 GMT
i acutally thought of changing the way the information is being stored in the
database but i really want to find out how to make it work with the yes/no data
type, i reread my post and i think its a bit confusing the way i worded
everything lol but basically there is a yes/no data type in microsoft access
and i want to display this on a web page and if its yes in the database i want
a checkbox checked to be displayed on the web page and if its no in the
database i want the checkbox to appear unchecked on the web page, i also need
to be able to check or uncheck the checkbox on the webpage and submit the form
and have the changes made in the database, does anyone know how i could do
this?? the current way i have this set up is causing me a lot of errors and i
cant see to get it to work...
i appreciate the help and would appreciate any more help that maybe given to
assist me at making this work, thank you.
JMGibson3 - 30 Mar 2006 17:29 GMT
Can't help much.  All my inherited Yes/No's are long gone.  But I think Yes was
a negative 1 and No was a zero, strange huh. so something like ought to work:
<cfquery ......
UPDATE myTable
SET myCheckBox = <cfif isDefined("Form.myCheckBox")>-1<cfelse>0</cfif>
</cfquery>
It might also depend on what Driver version is passing the query along.  If
above doesn't work experiment with Yes and No, or True and False, both with and
without quotes.  
Merle_Hanson - 30 Mar 2006 19:25 GMT
U have to set ur values to either 1 or 0... 1 for yes or 0 for No...
I have done this using a cfif...
ie: Try this - using radio button for yes/no...
<form>
<input type="radio" name="yesno" value="1" <cfif yesno is "1">checked</cfif>
Yes
<input type="radio" name="yesno" value="0" <cfif yesno is "0">checked</cfif> No
</form>

As for updating database...
Just do a CFUPDATE...
U will need the unique id in the form though for the update...
So put it in a hidden field...

<form action="passtoupdate.cfm">
input type=radio as above...

<input type="hidden" name="uniqueid" value="123">
</form>
Each database record usually has a unique key to that record...

passtoupdate.cfm

<cfupdate datasource="dataname" tablename="tableB">
WOLFcfm - 30 Mar 2006 21:19 GMT
so if the checkbox is unchecked on the web page it goes as undefined in the
form??
i'm going to try some of these methods out and see which one works best,
appreciate all the help and i'll keep everyone posted if i got it working or
not....
Not Nick - 31 Mar 2006 03:45 GMT
If the checkbox is unchecked, it never leaves the form, so it will not be
defined on the recieving page. So you have two possibilities:

1. <cfif NOT isDefined("form.myCheckbox")>
      <cfset form.myCheckbox = 0>
   <cfelse >
      <cfset form.myCheckbox = 1>
    </cfif>

2. <cfparam name="form.myCheckbox" default ="0">

You also have the YesNoFormat(value) function to play with.
Nightfall_Blue - 31 Mar 2006 09:35 GMT
If its any help I had this only a week or so ago.

The Checkbox info is Submitted like this on the form
----------------------------------------------------------------

Landmail
<input name="land_mail_marketing" type="checkbox" id="land_mail_marketing"
tabindex="29" title="Can we send you land mail messages" value="yes"/>
-----------------------------------------------------------------

Its written to the database (for the first time) like this in the insert
statement

<cfif IsDefined("FORM.land_mail_marketing")>
'Y'
<cfelse>
'N'
</cfif>

---------------------------------------------------------------

This Is how I got it working in the UPDATE form .

<cfif #account_info.email_marketing_info# EQ 'N'>
<input name="email_marketing_info" type="checkbox" id="email_marketing_info"
tabindex="27" title="Do you want emails from us" value="Y" />
<cfelse>
<input name="email_marketing_info" type="checkbox" id="email_marketing_info"
tabindex="27" title="Do you want emails from us" value="Y"  checked="checked"  
/>
</cfif>

--------------------------------------------------------------------
and updated on the database like this

land_mail_marketing =
<cfif IsDefined("FORM.land_mail_marketing") AND '#FORM.land_mail_marketing#'
EQ "Y"> 'Y'
<cfelse>'N'
</cfif>
,
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.