I'm trying to figure out how I can get an ASP form to dump the results in a database as well as email the results of the form out on a distribution list.
Depends on what you mean by "dump the results in a database". You mean form results being inserted into a Table, or extracting and displaying a table's contents? Whichever, the method I'd probably use is to simply set up the scripts like so:
===========================================================
'Do whatever you want to/from the database here
'
'
'
'The connect to your email list, build up your email object, and send it.
'
'
'
'
===========================================================
Can't be much more specific until I know what it is your trying to do......
The form is currently inserting the results of the form to a table. I need it so that when the user hits the send button it will email the results to my distribution list.
Ok, that's what I THOUGHT you were trying to do, but wasn't sure....
First thing, you can put both scripts on the same page, no problem. If you're going to be inserting the results into one table, then extracting your mailing list from another table (in the same DB file, I'm assuming for this example), and sending that list, then first you need to set up the ADO connection object. Something like this:
============================================================
Set connection = Server.CreateObject("ADODB.CONNECTION"
dbsource = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\yourdatabasefilepathhere'"
============================================================
Next, I would probably insert the form results, and be done with that step:
============================================================
Set insertsql = "INSERT INTO MyTableName (ColumnName1 , ColumnName2) VALUES=('"+Request.Form("formfield1"+"' , '"+Request.Form("formfield2"+"')"
And finally, your mailing list. As I have no idea what .asp component you're using for the smtp mailing I'll just show the email distribution extraction and let you plug in your mail sending routine...
Set connection2 = Server.CreateObject("ADODB.RECORDSET"
connection2.Open "SELECT Customername , Email FROM MyEmailDistTable" , connection 'uses your existing connection object...that way you're not making/disconnecting/remaking connections...your server will thank you.
Set custname = connection2("CustomerName"
Set em = connection2("Email"
do until connection2.EOF
'
'your mailing routine should go here....
'
connection2.MoveNext
loop
connection2.close
Set connection2 = Nothing
connection.close
Set connection = Nothing
============================================================
I've not debugged this script, so there may be a few glitches, but hopefully it's enough to give you a start on the right path. The whole, uninterupted script:
============================================================
Set connection = Server.CreateObject("ADODB.CONNECTION"
dbsource = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\yourdatabasefilepathhere'"
Set insertsql = "INSERT INTO MyTableName (ColumnName1 , ColumnName2) VALUES=('"+Request.Form("formfield1"+"' , '"+Request.Form("formfield2"+"')"
connection.Open dbsource
connection.Execute insertsql
Set connection2 = Server.CreateObject("ADODB.RECORDSET"
connection2.Open "SELECT Customername , Email FROM MyEmailDistTable" , connection 'uses your existing connection object...that way you're not making/disconnecting/remaking connections...your server will thank you.
Set custname = connection2("CustomerName"
Set em = connection2("Email"
do until connection2.EOF
'
'your mailing routine should go here....
'
connection2.MoveNext
loop
connection2.close
Set connection2 = Nothing
connection.close
Set connection = Nothing
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.