<% dim re dim msg dim referrerURL : referrerURL = Request.ServerVariables("HTTP_REFERER") dim cn, rs, strSQL, recordcount dim email : email = Request.form("EmailAddress") dim emailBody dim ourEmail : ourEmail = "dave@aroundhouston.com" dim ourEmailBody ' removes msg from the querystring, if present set re = New RegExp re.pattern = "(&|\?)?msg=[^&]*" referrerURL = re.replace(referrerURL, "") if email <> "" then ' checks if the email address already exists in the database strSQL = "SELECT * FROM Bands WHERE EmailAddress='" & email & "'" set cn = OpenConnection() set rs = cn.execute(strSQL) ' If the email address does not exist, insert it into the database. if rs.EOF then rs.close set rs = Nothing strSQL = "INSERT INTO Bands (EmailAddress) VALUES ('" & email & "')" cn.beginTrans cn.execute strSQL, recordcount if recordcount = 1 then cn.commitTrans cn.close set cn = Nothing else cn.rollbackTrans cn.close set cn = Nothing msg = "An error has occurred when recording your email address. Please try again." referrerURL = addToQueryString(referrerURL, msg) Response.redirect referrerURL end if else msg = "The email address " & email & " already exists in our records." referrerURL = addToQueryString(referrerURL, msg) Response.redirect referrerURL end if emailBody = "Thank you for subscribing to the Band Marketing Today Newsletter." & vbNewline & vbNewline & _ "http://www.bandmarketingtoday.com" SendMailMsg "info@aroundhouston.com", email, "", _ "Band Marketing Today Newsletter", emailBody, False ourEmailBody = "A band has signed up for the Band Marketing Today Newsletter. Their email is: " & _ email & ". It has been entered into the database (""/database/subscribers.mdb"")." & vbNewline & vbNewline & _ "http://www.bandmarketingtoday.com" SendMailMsg """Band Marketing Today"" ", ourEmail, "", _ "New Band Marketing Today Subscriber", ourEmailBody, False msg = "You signed up for " & email & ".
Thank you for subscribing to our newsletter!" referrerURL = addToQueryString(referrerURL, msg) Response.redirect referrerURL else Response.redirect referrerURL end if ' adds msg to the querystring (and does not interfere with any existing querystring variables) function addToQueryString(referrerURL, msg) if InStr(referrerURL, "?") > 0 then addToQueryString = referrerURL & "&msg=" & msg else addToQueryString = referrerURL & "?msg=" & msg end if end function %>