Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert and update record

Status
Not open for further replies.

stevemarsh99

Technical User
Aug 10, 2005
88
GB
I am trying to have a page with an update and a insert into 2 different tables but i can get the update but not the insert?

I have had a dabble in the evil code...and i created another sperate page that with a insert behaviour assigned to the form, i copied and pasted the code onto the other page, copied the variables...changes all the variables in the second section to MM_whatever2 and it posts the updates but not the insert command..any thoughts?

<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: set variables

If (CStr(Request("MM_update")) = "form1" And CStr(Request("MM_recordId")) <> "") Then

MM_editConnection = MM_ealert_STRING
MM_editTable = "tbl_ealert"
MM_editColumn = "MAGAZINEID"
MM_recordId = "" + Request.Form("MM_recordId") + ""
MM_editRedirectUrl = "../default.asp"
MM_fieldsStr = "LIST_ADV|value|LIST_CIRC|value|DIGITALISSUE|value|EDITORTEXT|value"
MM_columnsStr = "LIST_ADV|',none,''|LIST_CIRC|',none,''|DIGITALISSUE|',none,''|EDITORTEXT|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>

<%
' *** Edit Operations: declare variables

Dim MM_editAction2
Dim MM_abortEdit2
Dim MM_editQuery2
Dim MM_editCmd2

Dim MM_editConnection2
Dim MM_editTable2
Dim MM_editRedirectUrl2
Dim MM_editColumn2
Dim MM_recordId2

Dim MM_fieldsStr2
Dim MM_columnsStr2
Dim MM_fields2
Dim MM_columns2
Dim MM_typeArray2
Dim MM_formVal2
Dim MM_delim2
Dim MM_altVal2
Dim MM_emptyVal2
Dim MM_i2

MM_editAction2 = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction2 = MM_editAction2 & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit2 = false

' query string to execute
MM_editQuery2 = ""
%>

<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

MM_editConnection2 = MM_ealert_STRING
MM_editTable2 = "tbl_sentlog"
MM_editRedirectUrl2 = "Sent.asp"
MM_fieldsStr = "DIGITALISSUE|value|MAGAZINE|value"
MM_columnsStr2 = "DIGITALISSUE|',none,''|MAGAZINENAME|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields2 = Split(MM_fieldsStr2, "|")
MM_columns2 = Split(MM_columnsStr2, "|")

' set the form values
For MM_i2 = LBound(MM_fields2) To UBound(MM_fields2) Step 2
MM_fields2(MM_i2+1) = CStr(Request.Form(MM_fields2(MM_i2)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl2 <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl2, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl2 = MM_editRedirectUrl2 & "?" & Request.QueryString
Else
MM_editRedirectUrl2 = MM_editRedirectUrl2 & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues2
Dim MM_dbValues2

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues2 = ""
MM_dbValues2 = ""
For MM_i2 = LBound(MM_fields2) To UBound(MM_fields2) Step 2
MM_formVal2 = MM_fields(MM_i2+1)
MM_typeArray2 = Split(MM_columns(MM_i2+1),",")
MM_delim2 = MM_typeArray2(0)
If (MM_delim2 = "none") Then MM_delim2 = ""
MM_altVal2 = MM_typeArray2(1)
If (MM_altVal2 = "none") Then MM_altVal2 = ""
MM_emptyVal2 = MM_typeArray2(2)
If (MM_emptyVal2 = "none") Then MM_emptyVal2 = ""
If (MM_formVal2 = "") Then
MM_formVal2 = MM_emptyVal2
Else
If (MM_altVal2 <> "") Then
MM_formVal2 = MM_altVal2
ElseIf (MM_delim2 = "'") Then ' escape quotes
MM_formVal2 = "'" & Replace(MM_formVal2,"'","''") & "'"
Else
MM_formVal2 = MM_delim2 + MM_formVal2 + MM_delim2
End If
End If
If (MM_i2 <> LBound(MM_fields2)) Then
MM_tableValues2 = MM_tableValues2 & ","
MM_dbValues2 = MM_dbValues2 & ","
End If
MM_tableValues2 = MM_tableValues2 & MM_columns2(MM_i2)
MM_dbValues2 = MM_dbValues2 & MM_formVal2
Next
MM_editQuery2 = "insert into " & MM_editTable2 & " (" & MM_tableValues2 & ") values (" & MM_dbValues2 & ")"

If (Not MM_abortEdit2) Then
' execute the insert
Set MM_editCmd2 = Server.CreateObject("ADODB.Command")
MM_editCmd2.ActiveConnection = MM_editConnection2
MM_editCmd2.CommandText = MM_editQuery2
MM_editCmd2.Execute
MM_editCmd2.ActiveConnection.Close

If (MM_editRedirectUrl2 <> "") Then
Response.Redirect(MM_editRedirectUrl2)
End If
End If

End If
%>

<%
Dim rs_ealert__MMColParam
rs_ealert__MMColParam = "1"
If (Request.QueryString("MAGAZINEID") <> "") Then
rs_ealert__MMColParam = Request.QueryString("MAGAZINEID")
End If
%>
************************************************
Form:

<form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">
<p>
<br>
<input name="LIST_ADV" type="hidden" id="LIST_ADV" value="No">
<input name="LIST_CIRC" type="hidden" id="LIST_CIRC" value="No">
<input name="DIGITALISSUE" type="hidden" id="DIGITALISSUE" value="incomplete">
<input name="EDITORTEXT" type="hidden" id="EDITORTEXT" value="No">
<input name="MAGAZINE" type="hidden" id="MAGAZINE" value="<%=(rs_ealert.Fields.Item("MAGAZINENAME").Value)%>">
<input name="DATESENT" type="hidden" id="DATESENT" value="Sent on blah">
<br>
<br>
<input type="image" src="../images/SENTBUTTON.gif" name="Submit" value="Submit" >
</p>
<input type="hidden" name="MM_insert" value="form1">
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= rs_ealert.Fields.Item("MAGAZINEID").Value %>">
<br>
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top