Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dual methods for an asp form

Status
Not open for further replies.

Garabaldi

Technical User
Jan 16, 2002
61
CA
Folks,

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.

Does anyone know of a way to do this?
 
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......
 
AncientTiger,

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.

Thanks,
 
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")+"')"

connection.Open dbsource
connection.Execute insertsql
============================================================

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

============================================================


Hope this helped!
AT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top