asia_divine
01-25-2002, 03:41 AM
I have a form on my web site that a user can fill out.
What I would like is for the information that they submit sent to my database. Is it possible, if so how?
At the same time, I would like to receive an email telling me that a form has been filled in.
Please can you help?
Thanks,
Mike
BukHix
01-25-2002, 11:23 AM
asia_divine, yes it is possible and if you are familiar with HTML and VBA syntax it is also some what simple to do. Assuming you are on a Windows based server you could use ASP to accomplish it.
This is a quick and dirty example but it should give you an idea of the process.
<form method="POST" action="confirm.asp">
<p><input type="text" name="YourField" size="20">
<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2"></p>
</form>
I bolded the important part, that is where you want to name the page that you are going to use as a confirmation page. Now that you have your form page written you can create a new page named confirm.asp and put this in it:
<%
Dim strFrmText
strFrmText = Request.Form("YourField")
%>
<html>
<head>
<title>Confirm Page</title>
</head>
<body>
Thank you for submitting <% Response.Write(strFrmText) %>
</body>
</html>
Now when you submit the information on the first page you will be taken to the confirmation page which will say, Thank you for submitting xxxxxxxxxx.
But since you want to put the data in a database we have one more step to do. After you create your database with your table and fields import put it in a directory on your webserver. Now add this to the confirmation page.
<%
Dim strFrmText, objConn, objRs
strFrmText = Request.Form("YourField")
Const adLockOptimistic = 3
Const adCmdTable = &H0002
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" _
& Server.MapPath("/fpdb/YourDatabase.mdb")
objConn.Open
Set objRs = Server.CreateObject("ADODB.Recordset")
objRs.Open "YourTable", objconn, ,adLockOptimistic , adCmdTable
objRs.AddNew
objRs("YourField") = strFrmText
objRs.Update
objRs.Close
Set objRs = Nothing
objConn.Close
Set objConn = Nothing
%>
<html>
<head>
<title>Confirm Page</title>
</head>
<body>
Thank you for submitting <% Response.Write(strFrmText) %>. <br>
<% Response.Write(strFrmText) %> has been added to the database.
</body>
</html>
For the email part you use whatever email componant that your host or webserver provides. They all do basicaly the same thing and it is pretty easy to convert from one to the other. I use jmail so I will provide code for that but if you are using CDONTS or ASPMail it is going to be very similar.
Here is how it all looks together:
<%
Dim strFrmText, objConn, objRs, Mailer
strFrmText = Request.Form("YourField")
Const adLockOptimistic = 3
Const adCmdTable = &H0002
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" _
& Server.MapPath("/fpdb/YourDatabase.mdb")
objConn.Open
Set objRs = Server.CreateObject("ADODB.Recordset")
objRs.Open "YourTable", objconn, ,adLockOptimistic , adCmdTable
objRs.AddNew
objRs("YourField") = strFrmText
objRs.Update
objRs.Close
Set objRs = Nothing
objConn.Close
Set objConn = Nothing
%>
<html>
<head>
<title>Confirm Page</title>
</head>
<body>
Thank you for submitting <% Response.Write(strFrmText) %>. <br>
<% Response.Write(strFrmText) %> has been added to the database.
<%
Set Mailer = Server.CreateObject("JMail.SMTPMail")
Mailer.Sender= "webmaster@traitnet.com"
Mailer.SenderName = "Buk's Web Form"
Mailer.AddRecipient "BukHix@traitnet.com" ' send content to this recipient
Mailer.Subject = "Some One entered data on your form"
Mailer.ContentType = "text/html"
Mailer.Body = "Check your database because " & strFrmText & _
"has just been added to it."
Mailer.Execute
Set Mailer = Nothing
%>
</body>
</html>
[This message has been edited by BukHix (edited 01-25-2002).]
BukHix
01-29-2002, 01:00 PM
Mike,
Were you able to get this working?