// *** Edit Operations: declare variables // set the form action variable MM_editAction = CGI.SCRIPT_NAME; If (CGI.QUERY_STRING NEQ "") { MM_editAction = MM_editAction & "?" & CGI.QUERY_STRING; } // boolean to abort record edit MM_abortEdit = false; // query string to execute MM_editQuery = ""; // *** Insert Record: set variables If (IsDefined("MM_insert")) { MM_editDatasource = #MM_tlotc_DSN#; MM_editTable = "newsfile"; MM_editRedirectUrl = "main.cfm"; MM_fieldsStr = "Poster|value|Subject|value|newsitem|value|newstype|value"; MM_columnsStr = "Poster|',none,''|Subject|',none,''|newsitem|',none,''|newstype|none,none,NULL"; // create the MM_fields and MM_columns arrays MM_fields = ListToArray(MM_fieldsStr,"|"); MM_columns = ListToArray(MM_columnsStr,"|"); // set the form values For (i=1; i+1 LE ArrayLen(MM_fields); i=i+2) { MM_fields[i+1] = IIf(IsDefined(MM_fields[i]),"FORM." & MM_fields[i],DE("")); } // append the query string to the redirect URL If (MM_editRedirectUrl NEQ "" AND CGI.QUERY_STRING NEQ "") { If (Find("?", MM_editRedirectUrl) EQ 0) { MM_editRedirectUrl = MM_editRedirectUrl & "?" & CGI.QUERY_STRING; } Else { MM_editRedirectUrl = MM_editRedirectUrl & "&" & CGI.QUERY_STRING; } } } // *** Insert Record: construct a sql insert statement If (IsDefined("MM_insert")) { // create the insert sql statement MM_tableValues=""; MM_dbValues=""; For (i=1; i+1 LE ArrayLen(MM_fields); i=i+2) { FormVal = MM_fields[i+1]; MM_typesArray = ListToArray(MM_columns[i+1],","); Delim = IIf(MM_typesArray[1] NEQ "none","MM_typesArray[1]",DE("")); AltVal = IIf(MM_typesArray[2] NEQ "none","MM_typesArray[2]",DE("")); EmptyVal = IIf(MM_typesArray[3] NEQ "none","MM_typesArray[3]",DE("")); If (FormVal EQ "") { FormVal = EmptyVal; } Else { If (AltVal NEQ "") { FormVal = AltVal; } Else If (Delim EQ "'") { // escape quotes FormVal = "'" & Replace(FormVal,"'","''","ALL") & "'"; } Else { FormVal = Delim & FormVal & Delim; } } If (i GT 1) { MM_tableValues = MM_tableValues & ","; MM_dbValues = MM_dbValues & ","; } MM_tableValues = MM_tableValues & MM_columns[i]; MM_dbValues = MM_dbValues & FormVal; } MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"; } #PreserveSingleQuotes(MM_editQuery)# SELECT * FROM newsfile Add News Item Page
Poster:
Newstype:
Subject:
News Item: