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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASPEmail & Update record? 1

Status
Not open for further replies.

OnAFan

Technical User
Mar 13, 2002
120
US
Hello all,
I have a problem...I am using aspemail to mail a submitted form to be submitted to one person, and also the form being submitted should also update the database. I did the aspemail part first, and it worked fine. Now, after I added the update record behavior, all it does is update the record (no email.) Is it even possible to do both? Thank you in advance.
-Terry
 
Hey Terry,

Yeah, couple of different methods.

What I do is

put the form stuff into Dim's

like

<%
Dim strUserName
Dim strUserEmail
Dim strUserAddress
....

strUserName = request.form(&quot;txtUserName&quot;)
strUseremail = request.form(&quot;txtUserEmail&quot;)
......
%>

Then you can create an insert & then also use the str's for email info.

OR

You can on page one (where the form is) insert the record and forward to page 2 (the one to email). Create a recordset on page 2, order by TOP 1 * ID ORDER BY ID DESC.

change ID to your actual autonumber field.

Then you've got the stuff right there to pull out of the recordset - and put into your email. &quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
Hi Stuart,
I tried it, and am still running into problems. If you have a minute...could you take a look at what I have, and tell me what you see?? Thanks so much.

<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<!--#include file=&quot;../Connections/conMember.asp&quot; -->
<%
Dim strfldUser
Dim strfldEmail
Dim strfldPhone


strfldServe1 = Request.Form(&quot;fldUser&quot;)
strfldLat1 = Request.Form(&quot;fldEmail&quot;)
strfldLong1 = Request.Form(&quot;fldPhone&quot;)

%>
<%

If Request.Form(&quot;submit&quot;) = &quot;Submit&quot; Then

Set Mail = Server.CreateObject(&quot;Persits.MailSender&quot;)
Mail.Host = &quot;waterisac2.waterisac.org&quot; ' Specify a valid SMTP server mail.yourserver.com
Mail.AddAddress cStr(Request(&quot;varTo&quot;)) 'Recipient Email Address
Mail.From = cStr(Request(&quot;varFrom&quot;)) 'Senders Email Address
Mail.FromName = cStr(Request(&quot;varFromName&quot;)) ' Specify sender's name
Mail.AddAddress cStr(Request(&quot;varTo&quot;)) 'Recipient Email Address
'Mail.AddCC cStr(Request(&quot;varCC&quot;)) 'Carbon Copy Email Address
Mail.Subject = cStr(Request(&quot;varSubject&quot;)) 'Email Subject
Mail.Body = cStr(Request(&quot;strBody&quot;)) & vbcrlf&_
&quot;From: &quot; & cStr(Request(&quot;varFromName&quot;))& vbcrlf&_
&quot;Email: &quot; & cStr(Request(&quot;varFrom&quot;))& vbcrlf&_
&quot;Subject: &quot; & cStr(Request(&quot;varSubject&quot;))& vbcrlf&_
&quot;User: &quot; & cStr(Request(&quot;fldUser&quot;))& vbcrlf&_
&quot;Email: &quot; & cStr(Request(&quot;fldEmail&quot;))& vbcrlf&_
&quot;Phone: &quot; & cStr(Request(&quot;fldPhone&quot;))'& vbcrlf&_


On Error Resume Next
Mail.Send
Set Mail = Nothing 'Clean up your objects!!!
If Err <> 0 Then
Response.Write &quot;Error encountered: &quot; & Err.Description
End If

Response.Redirect(&quot;thanks.html&quot;)

End If

%>

<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=&quot;&quot;
MM_authFailedURL=&quot;login.asp&quot;
MM_grantAccess=false
If Session(&quot;MM_Username&quot;) <> &quot;&quot; Then
If (true Or CStr(Session(&quot;MM_UserAuthorization&quot;))=&quot;&quot;) Or _
(InStr(1,MM_authorizedUsers,Session(&quot;MM_UserAuthorization&quot;))>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = &quot;?&quot;
If (InStr(1,MM_authFailedURL,&quot;?&quot;) >= 1) Then MM_qsChar = &quot;&&quot;
MM_referrer = Request.ServerVariables(&quot;URL&quot;)
if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & &quot;?&quot; & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & &quot;accessdenied=&quot; & Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%>
<%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request(&quot;URL&quot;))
If (Request.QueryString <> &quot;&quot;) Then
MM_editAction = MM_editAction & &quot;?&quot; & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

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

If (CStr(Request(&quot;MM_update&quot;)) <> &quot;&quot; And CStr(Request(&quot;MM_recordId&quot;)) <> &quot;&quot;) Then

MM_editConnection = MM_conSearch_STRING
MM_editTable = &quot;dbo.tbUtility&quot;
MM_editColumn = &quot;fldUtil_ID&quot;
MM_recordId = &quot;&quot; + Request.Form(&quot;MM_recordId&quot;) + &quot;&quot;
MM_editRedirectUrl = &quot;thanks.html&quot;
MM_fieldsStr = &quot;fldUser|value|fldEmail|value|fldPhone|value|value&quot;
MM_columnsStr = &quot;fldUser|',none,''|fldEmail|',none,''|fldPhone|',none,''&quot;

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, &quot;|&quot;)
MM_columns = Split(MM_columnsStr, &quot;|&quot;)

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

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

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

If (CStr(Request(&quot;MM_update&quot;)) <> &quot;&quot; And CStr(Request(&quot;MM_recordId&quot;)) <> &quot;&quot;) Then

' create the sql update statement
MM_editQuery = &quot;update &quot; & MM_editTable & &quot; set &quot;
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),&quot;,&quot;)
Delim = MM_typeArray(0)
If (Delim = &quot;none&quot;) Then Delim = &quot;&quot;
AltVal = MM_typeArray(1)
If (AltVal = &quot;none&quot;) Then AltVal = &quot;&quot;
EmptyVal = MM_typeArray(2)
If (EmptyVal = &quot;none&quot;) Then EmptyVal = &quot;&quot;
If (FormVal = &quot;&quot;) Then
FormVal = EmptyVal
Else
If (AltVal <> &quot;&quot;) Then
FormVal = AltVal
ElseIf (Delim = &quot;'&quot;) Then ' escape quotes
FormVal = &quot;'&quot; & Replace(FormVal,&quot;'&quot;,&quot;''&quot;) & &quot;'&quot;
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & &quot;,&quot;
End If
MM_editQuery = MM_editQuery & MM_columns(i) & &quot; = &quot; & FormVal
Next
MM_editQuery = MM_editQuery & &quot; where &quot; & MM_editColumn & &quot; = &quot; & MM_recordId

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

If (MM_editRedirectUrl <> &quot;&quot;) Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim User_Profile__MMColParam
User_Profile__MMColParam = &quot;1&quot;
If (Session(&quot;MM_UserName&quot;) <> &quot;&quot;) Then
rsProfile__MMColParam = Session(&quot;MM_UserName&quot;)
End If
%>
<%

set rsMem = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rsMem.ActiveConnection = MM_conSearch_STRING
rsMem.Source = &quot;SELECT fldUtil_ID FROM dbo.tbLogin WHERE fldUsername='&quot; + Session(&quot;MM_UserName&quot;) + &quot;'&quot;
rsMem.CursorType = 0
rsMem.CursorLocation = 2
rsMem.LockType = 3
rsMem.Open()
rsMem_numRows = 0
%>

<%
set rsUtil = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rsUtil.ActiveConnection = MM_conSearch_STRING
rsUtil.Source = &quot;SELECT * FROM dbo.tbUtility WHERE fldUtil_ID = &quot; + Cstr(rsMem.Fields.Item(&quot;fldUtil_ID&quot;).Value)
rsUtil.CursorType = 0
rsUtil.CursorLocation = 2
rsUtil.LockType = 3
rsUtil.Open()
rsUtil_numRows = 0
%>
 
yea everythings kinda swapped around and such.

Try method two

Where you do the insert on the page with the form - then redirect to pagetwo.

On page two we'll just do the create recordset by ID descending, and do the mail. &quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
Got it!! Thanks a million Stuart.
 
anytime &quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top