macromedia.coldfusion.advanced_techniques
[Top] [All Lists]

Using session management on a DB function, please help

Subject: Using session management on a DB function, please help
From: "Irish-Phoenix"
Date: Fri, 7 Sep 2007 13:54:08 +0000 UTC
Newsgroups: macromedia.coldfusion.advanced_techniques

Hello;
 I am writting a little application that utalizes a table in my DB. It is like 
an on / off switch. I wanted to know if it is possible to make a session 
management script that will make this "switch" work for all the users that log 
into the web site. 

 I need it to be in the on position no matter if there is another user who 
turned it off at the same time. Also, when a new user logs into the site, it is 
always "on"

 I am attaching the code for the app so far, as it is now, when one user turns 
it off.. it is off for everyone. This is what I am trying to bypass. I need to 
use the DB so all the pages in the site realize that it is off or on and you 
won't have to turn it off or on everytime you go to a new page in the web site. 
Look at it like this. When you use like a flash site, you can turn off the 
sound and the whole site remembers it. Well I am trying to do it in CF dynamic 
site.

 Is it possible to do this with session management? If so, how would I write 
this. I do have session management enabled in my application.cfm file. this is 
where I would more then likely have to put this type of script so the whole 
site is managed by it.

 Attached is my code.

 Thank you

 Phoenix

 <!--- Inxex page of app: --->
 <cfquery name="soundRecord" dataSource="csee" maxRows=1>
        SELECT sound.soundOn AS ViewField1, sound.ID AS ID_Field
        FROM sound
        <cfif isDefined ("URL.RecordID")>
        WHERE sound.ID = #URL.RecordID#
        </cfif>
 </cfquery>
 <html>
 <head>
        <title>sound - View Record</title>
 </head>
 <body bgcolor="#FFFFFF">
 <cfoutput query="soundRecord">
 <table>
        <tr>
        <td width="66" align="left" valign="top"> <font size="2" face="Verdana, 
Arial, Helvetica, sans-serif">Sound is:</font></td>
        <td width="114" align="left" valign="top"><font size="2" face="Verdana, 
Arial, Helvetica, sans-serif"><cfif ViewField1 eq 
0>off<cfelse>on</cfif></font></td>
        </tr>
        <tr>
          <td colspan="2" align="left" valign="top"><form 
action="sound_RecordAction.cfm" method="post">
        <input type="hidden" name="RecordID" value="#ID_Field#">
        <input type="submit" name="btnView_Edit" value=" <cfif ViewField1 eq 
0>Turn 
sound on<cfelse>Turn sound off</cfif> ">
 </form></td>
     </tr>
 </table>
 </cfoutput>
 <a href="javascript:window.close();"><b>Close Window</b></a>
 </body></html>


 <!--- EDIT PAGE OF APP --->
 <cfset FormFieldList = "on">
 <cfif isDefined("URL.RecordID")>
        <cfquery name="soundRecord" dataSource="csee" maxRows=1>
                SELECT sound.soundOn, sound.ID AS ID_Field
                FROM sound
                <cfif isDefined ("URL.RecordID")>
                WHERE sound.ID = #URL.RecordID#
                </cfif>
        </cfquery>

        <cfif not ListFind( FormFieldList, "ID" )>
                <cfset FormFieldList = ListAppend( FormFieldList, "ID" )>
        </cfif>

                        
                        <cfset soundOn = #soundRecord.soundOn#>
                

 <cfelse>
                        <cfset soundOn = 0>
 </cfif>
 <html>
 <head>
        <title>sound - Edit Record</title>
 </head>
 <body bgcolor="#FFFFFF">
 <font size="+1">sound</font> <br>
 <font size="+2"><b>Edit Record</b></font>
 <cfoutput>
 <form action="sound_RecordAction.cfm" method="post">
 <input type="hidden" name="FieldList" value="#FormFieldList#">
 <cfif isDefined("URL.RecordID")>
        <input type="hidden" name="RecordID" value="#URL.RecordID#">
        <input type="hidden" name="ID" value="#URL.RecordID#">
 </cfif>
 <table>
 <tr>
        <td valign="top"> on: </td>
     <td>
            <input type="checkbox" name="soundOn" value="1"<CFIF #soundOn# is 
1> 
checked</CFIF>> 
        </td>
        </tr>
 </table>
 <input type="submit" name="btnEdit_OK" value="    OK    ">
 <input type="submit" name="btnEdit_Cancel" value="Cancel">
 </form>
 </cfoutput>
 </body>
 </html>


 <!--- ACTION PAGE OF APP --->
 <cfif isDefined ("Form.btnView_Edit")>
        <cflocation url="sound_RecordEdit.cfm?RecordID=#Form.RecordID#">
 </cfif>


 <cfif isDefined("Form.btnEdit_OK")>
        <cfif isDefined("Form.RecordID")>
        <cfparam name="form.soundOn" default="0"> 
                <cfquery datasource="#sitedatasource#" username="#siteUserID#" 
password="#sitePassword#">
                UPDATE sound
         SET soundOn = <cfqueryparam value="#form.soundOn#" 
cfsqltype="cf_sql_bit">
         WHERE ID = <cfqueryparam value="#form.RecordID#" 
cfsqltype="cf_sql_integer">
 </cfquery>
                <cflocation url="sound_RecordView.cfm?RecordID=#Form.RecordID#">
 </cfif></cfif>


<Prev in Thread] Current Thread [Next in Thread>