grafixgirl
asked on
Storing form values to db and sending email
Hi,
I am working on a form which requires form values to be stored in (Access) db and sending an email, by just one click of a button, I was able to do both things separately (one form stores values in db, other sends an email- which is double work), but how do i do it in one file:
Below is my code, and instead of having it in 3 different files, can I just do it all in one place- by just one click of a button:
(Note: The below code is functional with out errors)
resultpage.asp
-------------------------- ---------- ---------- ---------- ---------- ------
<%
Dim N_fname, N_lname, N_Department_Branch, S_fname, S_lname, Y_fname, Y_lname, Y_Department_Branch, Y_Phone, Y_email, Standard, Comments
Dim sConnString, connection, sSQL
N_fname = Request.Form("N_fname")
N_lname = Request.Form("N_lname")
N_Department_Branch = Request.form("N_Department _Branch")
S_fname = Request.form("S_fname")
S_lname = Request.form("S_lname")
Y_fname = Request.form("Y_fname")
Y_lname = Request.form("Y_lname")
Y_Department_Branch = Request.form("Y_Department _Branch")
Y_Phone = Request.form("Y_Phone")
Y_email = Request.form("Y_email")
Standard = Request.form("Standard")
Comments = Request.form("Comments")
sSQL = "INSERT into Award (N_fname, N_lname, N_Department_Branch, S_fname, S_lname, Y_fname, Y_lname, Y_Department_Branch, Y_Phone, Y_email, Standard, Comments) values ('" & N_fname & "', '" & N_lname & "', '" & N_Department_Branch & "', '" & S_fname & "', '" & S_lname & "', '" & Y_fname & "', '" & Y_lname & "', '" & Y_Department_Branch & "', '" & Y_Phone & "', '" & Y_email & "', '" & Standard &"', '" & Comments & "')"
sConnString="PROVIDER=Micr osoft.Jet. OLEDB.4.0; " & "Data Source=" & Server.MapPath("/db/db.mdb ")
Set connection = Server.CreateObject("ADODB .Connectio n")
connection.Open(sConnStrin g)
connection.execute(sSQL)
response.write "Thank you! The Form Information was Inserted Successfully in our Database."
connection.Close
Set connection = Nothing
%>
-------------------------- ---------- ---------- ---------- --
awarddb.asp
-------------------------- -------
<form action="resultpage.asp" method="post">
<!-- <input type="hidden" name="a" value="send"> -->
<tr>
<td><b>Nominee's First Name:</b></td>
<td><input size="25" name="N_fname" type="text" class="input" maxlength=50></td>
</tr>
<tr>
<td><b>Nominee's Last Name:</b></td>
<td><input size="25" name="N_lname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Department / Branch:</b></td>
<td><input size="25" name="N_Department_Branch" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Supervisor First Name:</b></td>
<td><input size="25" name="S_fname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Supervisor Last Name:</b></td>
<td><input size="25" name="S_lname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><b>Your First Name:</b></td>
<td><input size="25" name="Y_fname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Last Name:</strong></td>
<td><input size="25" name="Y_lname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Department:</strong></td>
<td><input size="25" name="Y_Department_Branch" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Phone:</strong></td>
<td><input size="25" name="Y_Phone" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Email:</strong></td>
<td><input size="25" name="Y_email" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Standard: </strong></td>
<td><select name="Standard" class="input" >
<option value="Our People">Our People</option>
<option value="Our Customers">Our Customers</option>
<option value="Community Banking Experience">Community Banking Experience</option>
<option value="Communication">Comm unication< /option>
<option value="Listen & Learn">Listen & Learn</option>
<option value="Performance">Perfor mance</opt ion>
<option value="Knowledge">Knowledg e</option>
<option value="Accuracy">Accuracy< /option>
<option value="Accountability">Acc ountabilit y</option>
<option value="Responsiveness">Res ponsivenes s</option>
</select> </td>
</tr>
<tr>
<td><strong>Comments: </strong></td>
<td><textarea name="Comments"></textarea ></td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input name="submit" type="submit" class="input2" value=" SEND ">
</div></td>
</tr>
</form>
-------------------------- ---------- ---------- -
awardEmail.db
-------------------------- ---------- ----------
<%
if request.form("a") = "send" then
Set objMessage = CreateObject("CDO.Message" )
objMessage.Subject = "Nomination"
objMessage.From = "cdsfdsfnl@blue.com"
'objMessage.To = "xxx@blue.com"
objMessage.To = "xyz@blue.com"
objMessage.HTMLBody = "Submitted by: "&request.form("Y_fname") &" " & vbcrlf&_
""&request.form("Y_lname") &"<br>" & vbcrlf&_
"Department / Branch: "&request.form("Y_Departme nt_Branch" )&"<br>" & vbcrlf&_
"Phone: "&request.form("Y_Phone")& "<br>" & vbcrlf&_
"Email: "&request.form("Y_email")& "<br>" & vbcrlf&_
"Standard: "&request.form("Standard") &"<br>" & vbcrlf&_
"Comments: "&request.form("Comments") &"<br><br> " & vbcrlf&_
"Nominee's First Name: "&request.form("N_fname")& "<br>" & vbcrlf&_
"Nominee's Last Name: "&request.form("N_lname")& "<br>" & vbcrlf&_
"Nominee's Department / Branch: "&request.form("N_Departme nt_Branch" )&"<br>" & vbcrlf&_
"Nominee's Supervisor-First Name: "&request.form("S_fname")& "<br>" & vbcrlf&_
"Nominee's Supervisor-Last Name: "&request.form("S_lname")& "<br>" & vbcrlf&_
""
objMessage.Configuration.F ields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.F ields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.202.11.233"
objMessage.Configuration.F ields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.F ields.Upda te
If Not blockAlerts Then
objMessage.Send
else
End If
Set objMessage = Nothing
response.redirect("resultp age.asp")
else
%>
<%'=N_fname%>
<table width="300" border="0" cellpadding="5" cellspacing="0">
<form action="" method="post">
<input type="hidden" name="a" value="send">
<tr>
<td><b>Nominee's First Name:</b></td>
<td><input size="25" name="N_fname" type="input" maxlength=50></td>
</tr>
<tr>
<td><b>Nominee's Last Name:</b></td>
<td><input size="25" name="N_lname" type="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Department / Branch:</b></td>
<td><input size="25" name="N_Department_Branch" type="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Supervisor First Name:</b></td>
<td><input size="25" name="S_fname" type="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Supervisor Last Name:</b></td>
<td><input size="25" name="S_lname" type="input" maxlength=25></td>
</tr>
<tr>
<td><b>Your First Name:</b></td>
<td><input size="25" name="Y_fname" type="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Last Name:</strong></td>
<td><input size="25" name="Y_lname" type="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Department:</strong></td>
<td><input size="25" name="Y_Department_Branch" type="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Phone:</strong></td>
<td><input size="25" name="Y_Phone" type="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Email:</strong></td>
<td><input size="25" name="Y_email" type="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Standard: </strong></td>
<td><select name="Standard" type="input" >
<option value="Our People">Our People</option>
<option value="Our Customers">Our Customers</option>
<option value="Community Banking Experience">Community Banking Experience</option>
<option value="Communication">Comm unication< /option>
<option value="Listen & Learn">Listen & Learn</option>
<option value="Performance">Perfor mance</opt ion>
<option value="Knowledge">Knowledg e</option>
<option value="Accuracy">Accuracy< /option>
<option value="Accountability">Acc ountabilit y</option>
<option value="Responsiveness">Res ponsivenes s</option>
</select> </td>
</tr>
<tr>
<td><strong>Comments: </strong></td>
<td><textarea name="Comments" type="input" ></textarea></td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input name="Action" type="submit" class="input2" value=" SEND ">
</div></td>
</tr>
</form>
I am working on a form which requires form values to be stored in (Access) db and sending an email, by just one click of a button, I was able to do both things separately (one form stores values in db, other sends an email- which is double work), but how do i do it in one file:
Below is my code, and instead of having it in 3 different files, can I just do it all in one place- by just one click of a button:
(Note: The below code is functional with out errors)
resultpage.asp
--------------------------
<%
Dim N_fname, N_lname, N_Department_Branch, S_fname, S_lname, Y_fname, Y_lname, Y_Department_Branch, Y_Phone, Y_email, Standard, Comments
Dim sConnString, connection, sSQL
N_fname = Request.Form("N_fname")
N_lname = Request.Form("N_lname")
N_Department_Branch = Request.form("N_Department
S_fname = Request.form("S_fname")
S_lname = Request.form("S_lname")
Y_fname = Request.form("Y_fname")
Y_lname = Request.form("Y_lname")
Y_Department_Branch = Request.form("Y_Department
Y_Phone = Request.form("Y_Phone")
Y_email = Request.form("Y_email")
Standard = Request.form("Standard")
Comments = Request.form("Comments")
sSQL = "INSERT into Award (N_fname, N_lname, N_Department_Branch, S_fname, S_lname, Y_fname, Y_lname, Y_Department_Branch, Y_Phone, Y_email, Standard, Comments) values ('" & N_fname & "', '" & N_lname & "', '" & N_Department_Branch & "', '" & S_fname & "', '" & S_lname & "', '" & Y_fname & "', '" & Y_lname & "', '" & Y_Department_Branch & "', '" & Y_Phone & "', '" & Y_email & "', '" & Standard &"', '" & Comments & "')"
sConnString="PROVIDER=Micr
Set connection = Server.CreateObject("ADODB
connection.Open(sConnStrin
connection.execute(sSQL)
response.write "Thank you! The Form Information was Inserted Successfully in our Database."
connection.Close
Set connection = Nothing
%>
--------------------------
awarddb.asp
--------------------------
<form action="resultpage.asp" method="post">
<!-- <input type="hidden" name="a" value="send"> -->
<tr>
<td><b>Nominee's First Name:</b></td>
<td><input size="25" name="N_fname" type="text" class="input" maxlength=50></td>
</tr>
<tr>
<td><b>Nominee's Last Name:</b></td>
<td><input size="25" name="N_lname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Department / Branch:</b></td>
<td><input size="25" name="N_Department_Branch"
</tr>
<tr>
<td><b>Nominee's Supervisor First Name:</b></td>
<td><input size="25" name="S_fname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Supervisor Last Name:</b></td>
<td><input size="25" name="S_lname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><b>Your First Name:</b></td>
<td><input size="25" name="Y_fname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Last Name:</strong></td>
<td><input size="25" name="Y_lname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Department:</strong></td>
<td><input size="25" name="Y_Department_Branch"
</tr>
<tr>
<td><strong>Your Phone:</strong></td>
<td><input size="25" name="Y_Phone" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Email:</strong></td>
<td><input size="25" name="Y_email" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Standard: </strong></td>
<td><select name="Standard" class="input" >
<option value="Our People">Our People</option>
<option value="Our Customers">Our Customers</option>
<option value="Community Banking Experience">Community Banking Experience</option>
<option value="Communication">Comm
<option value="Listen & Learn">Listen & Learn</option>
<option value="Performance">Perfor
<option value="Knowledge">Knowledg
<option value="Accuracy">Accuracy<
<option value="Accountability">Acc
<option value="Responsiveness">Res
</select> </td>
</tr>
<tr>
<td><strong>Comments: </strong></td>
<td><textarea name="Comments"></textarea
</tr>
<tr>
<td colspan="2">
<div align="center">
<input name="submit" type="submit" class="input2" value=" SEND ">
</div></td>
</tr>
</form>
--------------------------
awardEmail.db
--------------------------
<%
if request.form("a") = "send" then
Set objMessage = CreateObject("CDO.Message"
objMessage.Subject = "Nomination"
objMessage.From = "cdsfdsfnl@blue.com"
'objMessage.To = "xxx@blue.com"
objMessage.To = "xyz@blue.com"
objMessage.HTMLBody = "Submitted by: "&request.form("Y_fname") &" " & vbcrlf&_
""&request.form("Y_lname")
"Department / Branch: "&request.form("Y_Departme
"Phone: "&request.form("Y_Phone")&
"Email: "&request.form("Y_email")&
"Standard: "&request.form("Standard")
"Comments: "&request.form("Comments")
"Nominee's First Name: "&request.form("N_fname")&
"Nominee's Last Name: "&request.form("N_lname")&
"Nominee's Department / Branch: "&request.form("N_Departme
"Nominee's Supervisor-First Name: "&request.form("S_fname")&
"Nominee's Supervisor-Last Name: "&request.form("S_lname")&
""
objMessage.Configuration.F
objMessage.Configuration.F
objMessage.Configuration.F
objMessage.Configuration.F
If Not blockAlerts Then
objMessage.Send
else
End If
Set objMessage = Nothing
response.redirect("resultp
else
%>
<%'=N_fname%>
<table width="300" border="0" cellpadding="5" cellspacing="0">
<form action="" method="post">
<input type="hidden" name="a" value="send">
<tr>
<td><b>Nominee's First Name:</b></td>
<td><input size="25" name="N_fname" type="input" maxlength=50></td>
</tr>
<tr>
<td><b>Nominee's Last Name:</b></td>
<td><input size="25" name="N_lname" type="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Department / Branch:</b></td>
<td><input size="25" name="N_Department_Branch"
</tr>
<tr>
<td><b>Nominee's Supervisor First Name:</b></td>
<td><input size="25" name="S_fname" type="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Supervisor Last Name:</b></td>
<td><input size="25" name="S_lname" type="input" maxlength=25></td>
</tr>
<tr>
<td><b>Your First Name:</b></td>
<td><input size="25" name="Y_fname" type="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Last Name:</strong></td>
<td><input size="25" name="Y_lname" type="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Department:</strong></td>
<td><input size="25" name="Y_Department_Branch"
</tr>
<tr>
<td><strong>Your Phone:</strong></td>
<td><input size="25" name="Y_Phone" type="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Email:</strong></td>
<td><input size="25" name="Y_email" type="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Standard: </strong></td>
<td><select name="Standard" type="input" >
<option value="Our People">Our People</option>
<option value="Our Customers">Our Customers</option>
<option value="Community Banking Experience">Community Banking Experience</option>
<option value="Communication">Comm
<option value="Listen & Learn">Listen & Learn</option>
<option value="Performance">Perfor
<option value="Knowledge">Knowledg
<option value="Accuracy">Accuracy<
<option value="Accountability">Acc
<option value="Responsiveness">Res
</select> </td>
</tr>
<tr>
<td><strong>Comments: </strong></td>
<td><textarea name="Comments" type="input" ></textarea></td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input name="Action" type="submit" class="input2" value=" SEND ">
</div></td>
</tr>
</form>
I had a typo, you can remove the line response.write "Thank you! The Form Information was Inserted Successfully in our Database." from the code i have pasted above.
Cheers do let me know if you have doubts...
Cheers do let me know if you have doubts...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
--------------------------
awarddb.asp
--------------------------
<form action="awarddb.asp?Update
<!-- <input type="hidden" name="a" value="send"> -->
<tr>
<td><b>Nominee's First Name:</b></td>
<td><input size="25" name="N_fname" type="text" class="input" maxlength=50></td>
</tr>
<tr>
<td><b>Nominee's Last Name:</b></td>
<td><input size="25" name="N_lname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Department / Branch:</b></td>
<td><input size="25" name="N_Department_Branch"
</tr>
<tr>
<td><b>Nominee's Supervisor First Name:</b></td>
<td><input size="25" name="S_fname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><b>Nominee's Supervisor Last Name:</b></td>
<td><input size="25" name="S_lname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><b>Your First Name:</b></td>
<td><input size="25" name="Y_fname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Last Name:</strong></td>
<td><input size="25" name="Y_lname" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Department:</strong></td>
<td><input size="25" name="Y_Department_Branch"
</tr>
<tr>
<td><strong>Your Phone:</strong></td>
<td><input size="25" name="Y_Phone" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Your Email:</strong></td>
<td><input size="25" name="Y_email" type="text" class="input" maxlength=25></td>
</tr>
<tr>
<td><strong>Standard: </strong></td>
<td><select name="Standard" class="input" >
<option value="Our People">Our People</option>
<option value="Our Customers">Our Customers</option>
<option value="Community Banking Experience">Community Banking Experience</option>
<option value="Communication">Comm
<option value="Listen & Learn">Listen & Learn</option>
<option value="Performance">Perfor
<option value="Knowledge">Knowledg
<option value="Accuracy">Accuracy<
<option value="Accountability">Acc
<option value="Responsiveness">Res
</select> </td>
</tr>
<tr>
<td><strong>Comments: </strong></td>
<td><textarea name="Comments"></textarea
</tr>
<tr>
<td colspan="2">
<div align="center">
<input name="submit" type="submit" class="input2" value=" SEND ">
</div></td>
</tr>
</form>
<%
If request.querystring("Updat
Dim N_fname, N_lname, N_Department_Branch, S_fname, S_lname, Y_fname, Y_lname, Y_Department_Branch, Y_Phone, Y_email, Standard, Comments
Dim sConnString, connection, sSQL
N_fname = Request.Form("N_fname")
N_lname = Request.Form("N_lname")
N_Department_Branch = Request.form("N_Department
S_fname = Request.form("S_fname")
S_lname = Request.form("S_lname")
Y_fname = Request.form("Y_fname")
Y_lname = Request.form("Y_lname")
Y_Department_Branch = Request.form("Y_Department
Y_Phone = Request.form("Y_Phone")
Y_email = Request.form("Y_email")
Standard = Request.form("Standard")
Comments = Request.form("Comments")
sSQL = "INSERT into Award (N_fname, N_lname, N_Department_Branch, S_fname, S_lname, Y_fname, Y_lname, Y_Department_Branch, Y_Phone, Y_email, Standard, Comments) values ('" & N_fname & "', '" & N_lname & "', '" & N_Department_Branch & "', '" & S_fname & "', '" & S_lname & "', '" & Y_fname & "', '" & Y_lname & "', '" & Y_Department_Branch & "', '" & Y_Phone & "', '" & Y_email & "', '" & Standard &"', '" & Comments & "')"
sConnString="PROVIDER=Micr
Set connection = Server.CreateObject("ADODB
connection.Open(sConnStrin
connection.execute(sSQL)
response.write "Thank you! The Form Information was Inserted Successfully in our Database."
Set objMessage = CreateObject("CDO.Message"
objMessage.Subject = "Nomination"
objMessage.From = "cdsfdsfnl@blue.com"
'objMessage.To = "xxx@blue.com"
objMessage.To = "xyz@blue.com"
objMessage.HTMLBody = "Submitted by: "&request.form("Y_fname") &" " & vbcrlf&_
""&request.form("Y_lname")
"Department / Branch: "&request.form("Y_Departme
"Phone: "&request.form("Y_Phone")&
"Email: "&request.form("Y_email")&
"Standard: "&request.form("Standard")
"Comments: "&request.form("Comments")
"Nominee's First Name: "&request.form("N_fname")&
"Nominee's Last Name: "&request.form("N_lname")&
"Nominee's Department / Branch: "&request.form("N_Departme
"Nominee's Supervisor-First Name: "&request.form("S_fname")&
"Nominee's Supervisor-Last Name: "&request.form("S_lname")&
""
objMessage.Configuration.F
objMessage.Configuration.F
objMessage.Configuration.F
objMessage.Configuration.F
If Not blockAlerts Then
objMessage.Send
else
End If
Set objMessage = Nothing
response.redirect("thankYo
connection.Close
Set connection = Nothing
End If
%>