View Full Version : ASP Form to Email and MS DB
skhan1021
07-08-2005, 05:06 PM
Problem: I can't get my form to send an email and update my MS db when the user checks a checkbox in the form. At this point I have it doing one or the other. For example, when the checkbox is checked it will send the email but it will not enter a record in my db and when the checkbox is not checked it will update the record in my db. Can anyone shed some light on my problem? I would greatly appreciate it.
Thanks,
Sam
miranda
07-09-2005, 03:14 PM
try showing the code in question. It is difficult to surmise what the problem may be if we don't see what the code is.
skhan1021
07-11-2005, 02:26 PM
Good point... Here it is...
Code for form:
<HTML>
<HEAD>
<TITLE>Survey</TITLE>
<STYLE>
td
{
font-family: tahoma,
arial, helvetica;
font-size: 10pt;
color: #000000;
}
</STYLE>
</HEAD>
<BODY BGCOLOR="#1F92C8" TOPMARGIN="60" LEFTMARGIN="0" RIGHTMARGIN="0">
<CENTER>
<TABLE BORDER="1" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
<FORM METHOD="POST" ACTION="survey.asp">
<TR>
<TD ALIGN="CENTER" BGCOLOR="#fdf9ce">
<TABLE BORDER="0" CELLPADDING="5" CELLSPACING="0">
<TR>
<TD ALIGN="RIGHT">Tech Number:</TD>
<TD ALIGN="LEFT"><INPUT TYPE="text" SIZE="4" MAXLENGTH="4" NAME="tech"></TD>
<TD WIDTH="180PX"> </TD>
<TD ALIGN="RIGHT">Mgmt Area:</TD>
<TD ALIGN="LEFT"><INPUT TYPE="text" SIZE="2" MAXLENGTH="2" NAME="mgmt"></TD>
</TR>
<TR>
<TD ALIGN="RIGHT">Type of Job:</TD>
<TD ALIGN="LEFT"><INPUT TYPE="text" SIZE="2" MAXLENGTH="2" NAME="jobtype"></TD>
<TD WIDTH="180PX"> </TD>
<TD ALIGN="RIGHT">Job Number:</TD>
<TD ALIGN="LEFT"><INPUT TYPE="text" SIZE="6" MAXLENGTH="6" NAME="jobnumber"></TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD HEIGHT="50PX" BGCOLOR="#FFFFFF"> </TD>
</TR>
<TR>
<TD ALIGN="LEFT">
<TABLE BORDER="0" CELLPADDING="6" CELLSPACING="0" WIDTH="100%">
<TR>
<TD COLSPAN="3" BGCOLOR="#fdf9ce">1. Question 1?</TD>
</TR>
<TR>
<TD COLSPAN="3" BGCOLOR="#CC6633">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" BGCOLOR="#CC6633">
<TR>
<TD>
<INPUT TYPE="radio" NAME="question1" VALUE="Yes"> Yes</TD>
<TD WIDTH="50PX"> </TD>
<TD><INPUT TYPE="radio" NAME="question1" VALUE="No"> No</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD COLSPAN="3" BGCOLOR="#fdf9ce">2. Question 2?</TD>
</TR>
<TR>
<TD COLSPAN="3" BGCOLOR="#CC6633">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" BGCOLOR="#CC6633">
<TR>
<TD>
<INPUT TYPE="radio" NAME="question2" VALUE="Yes"> Yes</TD>
<TD WIDTH="50PX"> </TD>
<TD><INPUT TYPE="radio" NAME="question2" VALUE="No"> No</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD COLSPAN="3" BGCOLOR="#fdf9ce">3. Question 3?</TD>
</TR>
<TR>
<TD COLSPAN="3" BGCOLOR="#CC6633">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" BGCOLOR="#CC6633">
<TR>
<TD>
<INPUT TYPE="radio" NAME="question3" VALUE="Yes"> Yes</TD>
<TD WIDTH="50PX"> </TD>
<TD><INPUT TYPE="radio" NAME="question3" VALUE="No"> No</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD COLSPAN="3" BGCOLOR="#fdf9ce">4. Question 4?</TD>
</TR>
<TR>
<TD COLSPAN="3" BGCOLOR="#CC6633">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" BGCOLOR="#CC6633">
<TR>
<TD>
<INPUT TYPE="radio" NAME="question4" VALUE="Yes"> Yes</TD>
<TD WIDTH="50PX"> </TD>
<TD><INPUT TYPE="radio" NAME="question4" VALUE="No"> No</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD COLSPAN="3" BGCOLOR="#fdf9ce">5. Question 5?</TD>
</TR>
<TR>
<TD COLSPAN="3" BGCOLOR="#CC6633">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR>
<TD BGCOLOR="#CC6633">
<INPUT TYPE="radio" NAME="question5" VALUE="Yes"> Yes</TD>
<TD BGCOLOR="#CC6633" WIDTH="50PX"> </TD>
<TD BGCOLOR="#CC6633"><INPUT TYPE="radio" NAME="question5" VALUE="No"> No</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD COLSPAN="3" BGCOLOR="#fdf9ce">Comments:</TD>
</TR>
<TR>
<TD COLSPAN="3" BGCOLOR="#fdf9ce"><TEXTAREA NAME="comments" ROWS="5" COLS="40"></TEXTAREA></TD>
</TR>
<TR>
<TD COLSPAN="3" ALIGN="CENTER">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" BGCOLOR="#CC6633">
<TR>
<TD VALIGN="TOP"><INPUT TYPE="checkbox" NAME="sendback" VALUE="Yes"></TD>
<TD WIDTH="440PX"><--- Check here if any of the above questions were marked "No". (Email will be sent )</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD WIDTH="80PX"><INPUT TYPE="submit" VALUE="Submit Survey"></TD>
<TD WIDTH="150PX"><INPUT TYPE="reset" VALUE="Reset Survey"></TD>
<TD> </TD>
</TR>
</FORM>
</TABLE>
</BODY>
</HTML>
Below is the asp code:
<%
Tech = Request.Form("tech")
Mgmt = Request.Form("mgmt")
JobType = Request.Form("jobtype")
JobNumber = Request.Form("jobnumber")
Question1 = Request.Form("question1")
Question2 = Request.Form("question2")
Question3 = Request.Form("question3")
Question4 = Request.Form("question4")
Question5 = Request.Form("question5")
Comments = Request.Form("comments")
Sendback = Request.Form("sendback")
Dim strSql
strSql = "INSERT INTO callback(tech, mgmt, jobtype, jobnumber, question1, question2, question3, question4, question5, comments, sendback) VALUES ('" & tech & "','" & mgmt & "','" & jobtype & "','" & jobnumber & "','" & question1 & "','" & question2 & "','" & question3 & "','" & question4 & "','" & question5 & "','" & comments & "','" & sendback & "')"
Dim objCmd
Set objCmd = Server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = "Driver={Microsoft Access Driver (*.MDB)}; DBQ=" & Server.Mappath("SURVEY.mdb")
objCmd.CommandText = strSql
objCmd.Execute
Set objCmd = Nothing
Dim objCDOMail 'Define the email connection
Dim strbody 'Defines the body of the email
strbody = strbody & "<br><b>Tech: </b>" & Request.Form("tech")
strbody = strbody & "<br><b>Mgmt Area: </b>" & Request.Form("mgmt")
strbody = strbody & "<br><b>Job Type: </b>" & Request.Form("jobtype")
strbody = strbody & "<br><b>Job Number: </b>" & Request.Form("jobnumber")
strbody = strbody & "<br><br><br><b>Question 1? </b>" & Request.Form("question1")
strbody = strbody & "<br><br><b>Question 2? </b>" & Request.Form("question2")
strbody = strbody & "<br><br><b>Question 3? </b>" & Request.Form("question3")
strbody = strbody & "<br><br><b>Question 4? </b>" & Request.Form("question4")
strbody = strbody & "<br><br><b>Question 5? </b>" & Request.Form("question5")
strbody = strbody & "<hr><br><b>Comments: </b><br>" & Request.Form("comments")
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
objCDOMail.From = "sk@mydomain.com"
objCDOMail.To = "sk@mydomain.com"
objCDOMail.Cc = ""
objCDOMail.Bcc = ""
objCDOMail.Subject = "Survey: " & Request.Form("tech")
objCDOMail.BodyFormat = 0
objCDOMail.MailFormat = 0
objCDOMail.Body = strbody
objCDOMail.Importance = 1
objCDOMail.Send
Set objCDOMail = Nothing
%>
Basically at this point it will submit to both database and email but if the end user checks "sendback" that when I want the email to be sent and a new record added to the database. Any help will be greatly appreciated.
Thanks!
miranda
07-11-2005, 04:02 PM
OK, you have no control structure like an If/Else statement or a select case statement to look for the checkbox being marked. If a condition needs to occur dependant upon the user checking the box you need to show that in your asp code.
BTW you should use CDOSYS instead of CDONTS. CDONTS was depricated after Windows NT. While the .dll was included in Win2K it wasn't included in Windows 2003 Server or Windows XP.
skhan1021
07-11-2005, 04:24 PM
Can you show that in the code? I am kind of at a lose here...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.