Howdy Amy,
I really like
ASP Faq, it has a lot of useful information that is laid out in a user-friendly way. Just type in something like "update database", "open connection" or anything like that, and it will display something useful for you.
Quote:
|
So I need the web file to be able to modify a database and display the results at the current time and E-mail when certain conditions are met.
|
That doesn't sound too difficult, the only difficult part is being sure that your server can send email (you have to have CDO, CDONTS, or ASPEmail installed).
A while ago, someone asked me how to write user comments into a database and display those comments on another page. I wrote a few scripts that outlined how to do that, and they make a good general reference for understanding how to manipulate a database (at least in so far as adding and displaying records). I've attached a ZIP file with the scripts to this post, and you can see a working version of the script here:
http://www.fstdt.com/blog/cache/underemployed/index.asp
Sending an email that meets certain conditions basically works like this:
Code:
<%
Option Explicit
Dim DSNName, Conn, RS, sql1
Dim myMail
DSNName = "DRIVER=Microsoft Access Driver (*.mdb);DBQ="
DSNName = DSNName & Server.MapPath("mydata.mdb") '##### Change this line to the location of your database #####
DSNName = DSNName & ";PWD=" & "mypass" '##### Change this line to the password of your database #####
Set Conn = Server.CreateObject("ADODB.Connection") 'creating Connection and Recordset objects
Set RS = Server.CreateObject("ADODB.RecordSet")
sql1 = "Select * From your_table WHERE set conditions" 'You need to set some conditions for your WHERE clause. It is a prerequisite to know SQL before getting started, fortunately SQL isn't terribly difficult to learn.
Conn.Open DSNName
RS.Open sql1, Conn, 1, 1 'The "1, 1" means that we'll be opening the database in read-only mode,
'without making any modications to it.
if not rs.eof then 'EOF means "end of file", which happens if the SQL statement returns no results.
'We only enter the body of the IF if we find records that meet the defined conditions.
'We've found a record that matches criteria, so lets send and email
Set myMail=CreateObject("CDO.Message") 'Creating a mail object
myMail.Subject="Condition has been met" 'These are just generic fields, you should probably
myMail.From="mymail@mydomain.com" ' replace them with more useful information.
myMail.To="someone@somedomain.com"
myMail.TextBody="Dear Sir or Madam, please pick up your part."
myMail.Send
set myMail=nothing
end if
RS.Close
Conn.Close
set rs = nothing 'Make sure to clean up your variables and uninitializes objects
set conn = nothing
%>
If you want to access any of the fields from your table, use RS("
fieldname") to get it. For instance, you can make the following modifications:
Code:
if not rs.eof then 'EOF means "end of file", which happens if the SQL statement returns no results.
'We only enter the body of the IF if we find records that meet the defined conditions.
Dim clientName
clientName = RS("ClientName")
'We've found a record that matches criteria, so lets send and email
Set myMail=CreateObject("CDO.Message") 'Creating a mail object
myMail.Subject="Condition has been met" 'These are just generic fields, you should probably
myMail.From="mymail@mydomain.com" ' replace them with more useful information.
myMail.To="someone@somedomain.com"
myMail.TextBody="Dear " & ClientName & ", please pick up your part."
myMail.Send
set myMail=nothing
end if
If you need any more help, let me know
