By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,372 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

post to database AND send values into email and redirect user

P: 1
Hey,

I am having a user fill out a form then the fields are going to uploaded to my database. So, at this point, when the user hits the submit button I want three things to happen:

1. The form uploads to a database (the following code does this)

2. An e-mail is sent to my sales team as well as the customer, which contains the form values .

3. I want the user to then be directed automatically to another webpage, after they hit the submit button. (This page will read something like "Thank you for submitting your application).

I am able to do this on 2 seperate asp pages but when i try to do this on one asp page,its not working.

Please help me to solve this.

is it possible that once user hits submit button values of the form goes to insertintodatabase.asp and then somehow these values can move to sendemail.asp.please help me.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%>
  3.  
  4. <% 
  5. Dim thedate,Email,Customer,Contact,Phone,Fax,Address,City,State,Zip,part1,qty1,invoice1,po1,date1,serial1,problem1,part2,qty2,invoice2,po2,date2,serial2,problem2
  6. Dim part3,qty3,invoice3,po3,date3,serial3,problem3,part4,qty4,invoice4,po4,date4,serial4,problem4,terms,delivery,comments
  7. Dim sConnString, conn, sSQL, stSQL
  8. Dim MyNewRandomNum
  9. Randomize
  10. MyNewRandomNum = Int(Rnd * 10000000)+1
  11.  
  12. thedate=Request.form("thedate")
  13. Email=Request.form("Email")
  14. Customer=Request.form("Customer")
  15. Contact=Request.form("Contact")
  16. Phone=Request.form("Phone")
  17. Fax=Request.form("Fax")
  18. Address=Request.form("Address")
  19. City=Request.form("City")
  20. State=Request.form("State")
  21. Zip=Request.form("Zip")
  22. part1=Request.form("part1")
  23. qty1=Request.form("qty1")
  24. invoice1=Request.form("invoice1")
  25. po1=Request.form("po1")
  26. date1=Request.form("date1")
  27. serial1=Request.form("serial1")
  28. problem1=Request.form("problem1")
  29. part2=Request.form("part2")
  30. qty2=Request.form("qty2")
  31. invoice2=Request.form("invoice2")
  32. po2=Request.form("po2")
  33. date2=Request.form("date2")
  34. serial2=Request.form("serial2")
  35. problem2=Request.form("problem2")
  36. part3=Request.form("part3")
  37. qty3=Request.form("qty3")
  38. invoice3=Request.form("invoice3")
  39. po3=Request.form("po3")
  40. date3=Request.form("date3")
  41. serial3=Request.form("serial3")
  42. problem3=Request.form("problem3")
  43. part4=Request.form("part4")
  44. qty4=Request.form("qty4")
  45. invoice4=Request.form("invoice4")
  46. po4=Request.form("po4")
  47. date4=Request.form("date4")
  48. serial4=Request.form("serial4")
  49. problem4=Request.form("problem4")
  50. terms=Request.form("terms")
  51. delivery=Request.form("delivery")
  52. comments=Request.form("comments")
  53.  
  54. sSQL = "INSERT into rmarequest (req_no, date, email, company, contact, phone, fax, address, city, state, zip, part1, qty1, inv1, po1, inv_date1, serial1, problem1, part2, qty2, inv2, po2, inv_date2, serial2, problem2, part3, qty3, inv3, po3, inv_date3, serial3, problem3, part4, qty4, inv4, po4, inv_date4) values('" & MyNewRandomNum & "', '" & thedate & "','" & Email & "','" & Customer & "','" & Contact & "','" & Phone & "', '" & Fax & "', '" & Address & "', '" & City & "', '" & State & "','" & Zip & "', '" & part1 & "', '" & qty1 & "', '" & invoice1 & "', '" & po1 & "', '" & date1 & "', '" & serial1 & "', '" & problem1 & "', '" & part2 & "', '" & qty2 & "', '" & invoice2 & "', '" & po2 & "', '" & date2 & "', '" & serial2 & "', '" & problem2 & "', '" & part3 & "', '" & qty3 & "', '" & invoice3 & "', '" & po3 & "', '" & date3 & "', '" & serial3 & "', '" & problem3 & "', '" & part4 & "', '" & qty4 & "', '" & invoice4 & "', '" & po4 & "', '" & date4 & "')" 
  55. stSQL= "INSERT into rmarequest (serial4, problem4, terms, delivery, comments)values( '" & serial4 & "', '" & problem4 & "', '" & terms & "', '" & delivery & "', '" & Comments & "')"
  56.  
  57. Set conn = server.CreateObject("ADODB.connection")
  58. sConnString = "DRIVER=SQL Server;SERVER={};UID={}; PWD={};APP=;DATABASE={}" 
  59. conn.Open sConnString
  60. conn.execute(sSQL)
  61. conn.execute(stSQL)
  62. connection.Close
  63. Set conn = Nothing
  64. %><%
  65.  
  66. bodytext = ""
  67. bodytext = bodytext& "<HTML><HEAD><title>RMA Request Recieved@A3Net</title>"
  68. bodytext = bodytext&"<meta http-equiv=Content-Type content=text/css; charset=UTF-8>" 
  69. bodytext = bodytext&"<style fprolloverstyle>"
  70. bodytext = bodytext&"A:hover {color: #F6D271; font-weight: bold}.style6 {font-size: 10pt;font-weight: bold;}"
  71. bodytext = bodytext&".style7 {font-family: MS Sans Serif}.style8 {font-size: 10pt; font-weight: bold; font-family: MS Sans Serif; }"
  72. bodytext = bodytext&".style10 {font-family: MS Sans Serif;font-size: 1pt;color: #000066;font-weight: bold;}"
  73. bodytext = bodytext&".style13 {font-size: 10pt}.style14 {font-size: 1pt; color: #000066; font-family: MS Sans Serif;}"
  74. bodytext = bodytext&".style16 {font-family: MS Sans Serif;color: #003333;font-weight: bold;font-size: medium;}"
  75. bodytext = bodytext&".style17 {color: #336699}.style20 {font-family: Webdings; color: #DFAE0E;}"
  76. bodytext = bodytext&".style21 {font-size: 1pt}.style22 {font-size: 1pt; font-family: MS Sans Serif; }"
  77. bodytext = bodytext&".style24 {    font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;font-size: 9pt;}"
  78. bodytext = bodytext&".style25 { color: #000000;    font-size: 9px;}"
  79. bodytext = bodytext&"</style>"
  80. bodytext = bodytext&"</HEAD>"
  81. bodytext = bodytext&"<BODY BGCOLOR=#FFFFFF leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 link=#FFFFFF vlink=#FFFFFF alink=#FFFFFF>" 
  82.      bodytext = bodytext&"<span class=bodyplaingrey></span> <span class=bodyplainred></span> <span class=credit></span> "
  83.      bodytext = bodytext&"<span class=boldwhiteCopy></span> <span class=boldwhite></span> <span class=bodyplain></span> "
  84.      bodytext = bodytext&"<center>"
  85.      bodytext = bodytext&"<table border=1 cellpadding=0 cellspacing=0>"
  86. bodytext = bodytext&"<tr BGCOLOR=#cccccc><td align=center valign=middle><span class=style16>RMA Request Recieved@A3net</span></td>"
  87. bodytext = bodytext&"</tr><tr BGCOLOR=#e4e4e4><td align=center valign=middle><span class=style7>RMA Request Number:</span><span class=style24 style7 style13>&nbsp;&nbsp;"
  88.      bodytext = bodytext&MyNewRandomNum
  89.      bodytext = bodytext&"</span></td></tr><tr><td align=left valign=middle>"
  90.      bodytext = bodytext&"<table width=574 border=0 align=left cellpadding=0 cellspacing=0 bordercolor=#e2e2e2><tr>"
  91. bodytext = bodytext&"<td align=left valign=top class=style7>&nbsp;</td>"
  92. bodytext = bodytext&"<td align=left valign=top class=style6>&nbsp;</td></tr>"
  93.      bodytext = bodytext&"<tr><td align=left valign=top class=style7>&nbsp;</td>"
  94. bodytext = bodytext&"<td align=left valign=top class=style6>&nbsp;</td></tr>"
  95. bodytext = bodytext&"<tr bgcolor=#E4E4E4 height=30><td width=279 align=left valign=top class=style7><span class=style13><span class=style10>&nbsp;&nbsp;Request Date :</span></span><br><span class=style13>&nbsp;&nbsp;"
  96. bodytext = bodytext&thedate
  97.      bodytext = bodytext&"<br></span></td>"
  98. bodytext = bodytext&"<td width=288 align=left valign=top><span class=style10>&nbsp;&nbsp;Email:</span><br><span class=style24 style7 style13>&nbsp;&nbsp;"
  99.  
  100. bodytext = bodytext&"</table>"
  101.                                             bodytext = bodytext&"</td></tr><tr align=left valign=top><td colspan=2 class=style8>&nbsp;</td>"
  102.         bodytext = bodytext&"</tr><tr align=left valign=middle bgcolor=#E4E4E4><td height=30 colspan=2><span class=style10>&nbsp;&nbsp;Term of Exchange:</span><br><span class=style24 style7 style13>&nbsp;&nbsp;"
  103.                                             bodytext = bodytext&terms
  104. bodytext = bodytext&"</span></td></tr>"
  105.                                             bodytext = bodytext&"<tr align=left valign=top><td colspan=2 class=style8>&nbsp;</td></tr>"
  106.         bodytext = bodytext&"<tr align=left valign=top bgcolor=#E4E4E4 height=30><td colspan=2><span class=style10>&nbsp;&nbsp;Delivery Method:</span> <br><span class=style24 style7 style13>"
  107.         bodytext = bodytext&"&nbsp;&nbsp;"
  108.                                              bodytext = bodytext&delivery
  109.                                              bodytext = bodytext&"</span></td></tr><tr align=left valign=top><td colspan=2 class=style8>&nbsp;</td>"
  110.         bodytext = bodytext&"</tr><tr align=left valign=top bgcolor=#E4E4E4 height=20>"
  111.         bodytext = bodytext&"<td colspan=2><span class=style10>&nbsp;&nbsp;Explain Problem:</span><br>"
  112.          bodytext = bodytext&"&nbsp;&nbsp;<span class=style24 style7 style13>"
  113.                                             bodytext = bodytext&comments
  114.                                             bodytext = bodytext&"</span></td></tr><tr align=left valign=top><td colspan=2 class=style8>&nbsp;</td>"
  115.         bodytext = bodytext&"</tr><tr align=left valign=top><td colspan=2 class=style8>&nbsp;&nbsp;</td></tr></table>"
  116.                                              bodytext = bodytext&"</td></tr></table>"
  117.                                              bodytext = bodytext&"</center>"                                                                     
  118. bodytext = bodytext&"</BODY>" 
  119. bodytext = bodytext&"</HTML>"
  120.  
  121.  
  122. Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
  123.     Mailer.FromAddress = "sales@a3net.com"
  124.     Mailer.Cc = Email
  125.     Mailer.RemoteHost = "scriptmail.intermedia.net"
  126.     Mailer.AddRecipient "A3Net Servers Inc","rma@a3net.com"
  127.     Mailer.Subject = "A3net RMA Request("&MyNewRandomNum&")"
  128.     Mailer.ContentType = "text/html"
  129.     Mailer.BodyText = bodytext
  130.  
  131. if Mailer.SendMail then    'Message sent sucessfully
  132.     Response.Redirect "rmarequestsuccess.asp"
  133. else
  134.     Response.Redirect "rmarequestfailure.asp"
  135. end if
  136. %>
  137.  
  138. <%>
  139.  
Jul 15 '08 #1
Share this Question
Share on Google+
2 Replies


DrBunchman
Expert 100+
P: 979
Hi sindhudixit,

Welcome to Bytes.com! I hope you find the site useful.

What do you mean by "it's not working" when you try to do it all on one page? Is it throwing an error or are you not seeing the results you expect?

There's no reason why you can't do this all on one page but you could equally do it on two by passing the form values through the QueryString when you do a response.redirect.

Dr B
Jul 15 '08 #2

jhardman
Expert 2.5K+
P: 3,405
There's no reason why you can't do this all on one page but you could equally do it on two by passing the form values through the QueryString when you do a response.redirect
or you could put them all in session variables (I keep saying to do this, but the truth is, I am more likely to use DrBunchman's method)
Expand|Select|Wrap|Line Numbers
  1. for each x in request.form
  2.    session(x) = request.form(x)
  3. next
Jared
Jul 16 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.