PDA

View Full Version : another http header error question


CdnGal
03-06-2003, 07:50 AM
Hi, all

(newbie)
I've read the other postings regarding this error "The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content."
But still can't solve my problem. I DO have the buffer=true at the top as you'll see, but I still get the error. I've also tried putting response.clear just before my redirect. Here's some of the code. Any help would be greatly appreciated!

<%@ language="VBSCRIPT" %>
<% Response.Buffer = True %>
<!--#include virtual="/StudentWeb/PTetz/MCSP255/final/includes/adovbs.inc"-->
<!--#include virtual="/StudentWeb/PTetz/MCSP255/final/includes/vbUtils.asp"-->


<%
dim sSQL,oRST, oCN
Set oCN = OpenConnection() ''Open a database connection
%>


<%

dim done
done = request.form("done")
if done = "" then
done = "No"
%>
<html>
<head>
<title>Tell a friend</title>

<!--#include virtual="/StudentWeb/PTetz/MCSP255/final/includes/header.asp"-->

<!--#include virtual="/StudentWeb/PTetz/MCSP255/final/includes/left_sidebar.asp"-->

<td width="558" valign="top">
<h3>Refer a Friend!</h3>
Let your friend's know about our site! Your email addresses will not be shared with anyone.<br><br>

<body>
<table border="0" cellspacing="2" cellpadding="4" width=300>
<form action="default.asp" method="post">

<tr>
<td align=right>Your Name: </td>
<td><input type="text" name="sendername" size="25" maxlength="50"></td>
</tr>
<tr>
<td align=right>Your E-Mail: </td>
<td><input type="text" name="sendemail" size="25" maxlength="50"></td>
</tr>
<tr>
<td align=right>Friend's Name: </td>
<td><input type="text" name="friendname" size="25" maxlength="50"></td>
<tr>
<td align=right>Friend's E-Mail: </td>
<td><input type="text" name="friendemail" size="25" maxlength="50"><BR>
<input type="hidden" name="done" value="Yes"></td>
</tr>
<tr></tr>
<tr>
<td colspan=2><center><input type="submit" name="submit" value="Tell a friend!" ></center></td>
</tr>
</form>
</Table>

<%
Else
if request.form("done") = "Yes" then

'sets variables
dim sendmail, sendername, senderemail, friendname, friendemail
sendername = request.form("sendername")
senderemail = request.form("sendemail")
friendname = request.form("friendname")
friendemail = request.form("friendemail")
referdate = Date

Set sendmail = Server.CreateObject("CDONTS.NewMail")

'put the webmaster address here
sendmail.From = senderemail

'The mail is sent to the address entered in the previous page.
sendmail.To = friendemail

'Enter the subject of your mail here
sendmail.Subject = "Check out this website"

'send a specific page or send a site url
dim url
'url = Request.ServerVariables("HTTP_REFERER")
url = "http://bigal.itsm.macewan.ca/StudentWeb/PTetz/MCSP255/final/"

'This is the content of thr message.
sendmail.Body = "A great site recommendation from a friend!" & _
vbCrlf & vbCrlf & "Your friend " & sendername & " has sent you this email and thought you would should check out Artisan Metalworks." & _
vbCrlf & url & vbCrlf

'this sets mail priority.... 0=low 1=normal 2=high
sendmail.Importance = 1
sendmail.Send 'Send the email!



''if all went well, insert into database...

sSQL = "INSERT INTO tblAMReferAFriend "
sSQL = sSQL & "(refer_fname,refer_email,ref_friend_fname, ref_friend_email,refer_date)"
sSQL = sSQL & " VALUES ( "
sSQL = sSQL & "'" & sendername & "',"
sSQL = sSQL & "'" & senderemail & "',"
sSQL = sSQL & "'" & friendname & "',"
sSQL = sSQL & "'" & friendemail & "',"
sSQL = sSQL & "'" & referdate & "' "
sSQL = sSQL & ")"

dim oCmd
Set oCN = OpenConnection() ''Open a database connection
Set oCmd = ExecuteCommand(oCN,sSQL) ''Execute SQL
oCN.close()
Set oCmd=nothing
Set oCN=nothing


response.redirect "referthankyou.asp"
End if

End if
%>

<!--#include virtual="/StudentWeb/PTetz/MCSP255/final/includes/footer.asp"-->

Roy Sinclair
03-06-2003, 04:40 PM
Move the code with the redirect above the HTML code and also make sure you put the include for the footer with the HTML as well. Beyond that there's nothing I can see wrong with the way you have it right now but I can't see what might or might not be done by the vbutils.asp code either.

whammy
03-07-2003, 01:08 AM
Hey Roy, you're in Wichita? Omaha here. We're nearly neighbors! LOL ;)

I never noticed that. :)

Roy Sinclair
03-07-2003, 10:20 PM
Originally posted by whammy
Hey Roy, you're in Wichita? Omaha here. We're nearly neighbors! LOL ;)

I never noticed that. :)

Yep, that's about a 7 hour drive from here IIRC.

whammy
03-08-2003, 02:30 AM
:)

P.S. to get back on topic, Roy's suggestion should work just fine - if you need a QUICK fix, you might try using

<% Response.Buffer = True %>

After your <%@ Language %> statement -

BUT, even if that works, you're much better off understanding how ASP is processed (it is in every book, as far as I know), instead of resorting to ugly methods like that.

Personally, I only generate HTML as the very last step in my ASP program, using a subroutine, I just decide which subroutine to use depending upon logic.

This is not a bad way to do things, since it is about as modular as you can get using VBScript (unless you're using COM objects, DLL's etc., but it's still pretty much the same thing)... and it's the way I learned BASIC originally, many years ago.

Admittedly BASIC didn't have the capabilities of the OOP-oriented programming languages of today, but then neither does VBScript. ;)

Anyway... I hope that didn't confuse you (and I was generalizing), but what I do is usually something like this:

1. Use ASP logic to determine what HTML to display, unless there is a validation problem.
2. If there is a validation problem, go back to step 1.
3. Otherwise, display your HTML.

Of course this is a basic example, and you could have many branches to your logic... but...

The reason you're getting that error, is because these processes have been mixed up - you're already generating HTML, and then your program decides "hey, I'm not done yet!". ;)