5 Replies Latest reply on Aug 8, 2009 7:53 AM by salimzayat

    Update/Edit a database through cfajaxproxy

    salimzayat

      Hey all.  I have been trying to get this to work for two days and am stuck.  I want to be able to edit a database through a cfajaxproxy function.  Here is what I have:

       

      <cfajaxproxy cfc="#application.cfcRoot#schedulerFunctions" jsclassname="schedulerProxy">
              <script>
                  var schedulerProxy = new schedulerProxy();

                  schedulerProxy.setCallbackHandler( successHandler );
                  schedulerProxy.setErrorHandler( failHandler );

       

                  function updateGame( gameID, divID )
                  {

                      // grab these two values from two selection elements on the page
                      var homeTeam = document.getElementById( "select1" );
                      var visitorTeam = document.getElementById( "select2" );
                      gameProxy.updateGameMini( gameID, homeTeam.value, visitorTeam.value );
                  }
                 
                  function successHandler( result )
                  {
                      alert( result );
                  }
                 
                  function failHandler( statusCode, statusMsg )
                  {
                      alert( "failure" );
                      alert(statusCode+': '+statusMsg);
                  }           
              </script>

       

      And I have the aforementioned cfc with this.  In it, I want to update the games field with the two values.  So the meat of the function is:

       

          <cffunction name="updateGameMini" access="remote" returntype="query" output="false">
              <cfargument name="ID" type="string" requried="yes" hint="Game ID">
              <cfargument name="homeTeam" type="string" required="yes" hint="Home team unique ID">
              <cfargument name="visitorTeam" type="string" required="yes" hint="Visitor team unique ID">

       

                <cfquery name="myUpdateGame" datasource="#application.datasource#" username="#application.dbUser#" password="#application.dbPass#">
                  UPDATE games
                  SET home=<cfif arguments.homeTeam EQ "">NULL<Cfelse><cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.homeTeam#"></cfif>,
                  visitor=<cfif arguments.visitorTeam EQ "">NULL<Cfelse><cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.visitorTeam#"></cfif>
                  WHERE gameID=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.ID#">
              </cfquery>

       

                <cfreturn myUpdateGame>

          </cffunction>

       

      But I keep getting "500: Internal Server Error".  Why?  Is this possible to run an UPDATE database call through a cfajaxproxy cfc function?