Click to See Complete Forum and Search --> : [RESOLVED] Simple Guestbook Question


dtm32236
03-21-2008, 12:09 PM
Hi,

I found this very simple asp guestbook (http://www.haneng.com/Lessons_4.asp) and I have a question about the code.

The code is working fine, but there's a line that I don't understand:
MyFile = "c:\guestbook.txt"
I don't get this - where is this file? It's not on my hard drive (i've searched my entire computer for guestbook.txt), so, where can it be? :confused:

The code is simple:

Default.asp:
<form method="post" action="write.asp">
<p><label for="user_name">Name: </label><br><input name="user_name" type="text" size="35"></p>
<p><label for="user_name">Comments: </label><br><textarea rows="10" cols="30" name="new_line"></textarea></p>
<p><input type="submit" value="Post Comment"></p>
</form>
<br><br>
<%
MyFile = "c:\guestbook.txt"

'Opens the guestbook file if it exists
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
IF MyFileObj.FileExists(MyFile) THEN
Set MyTextFile=MyFileObj.OpenTextFile(MyFile)

'Reads a line, and outputs it
WHILE NOT MyTextFile.AtEndOfStream
%>
<hr>
<%=MyTextFile.ReadLine%>
<%
WEND

'Closes the textfile
MyTextFile.Close
END IF' Does file exist
%>

and Write.asp:
MyFile = "c:\guestbook.txt"

'Ready Scripting.FileSystemObject
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
'Opens textfile. 8 = add line to file, true = create if it doesn't exists
Set MyOutStream=MyFileObj.OpenTextFile(MyFile, 8, TRUE)

'Writes the line to the file
New_line = Request.Form("new_line")
New_line = Server.HTMLEncode(New_line)
'Writes the name to the file
User_name = Request.Form("user_name")
User_name = Server.HTMLEncode(User_name)
'Adds the time and date it was posted
New_line = "<I>Posted: " & NOW & "</I><BR>" & New_line
MyOutStream.WriteLine(User_name)
MyOutStream.WriteLine(New_line)

'Closes the file
MyOutStream.Close

'Sends them back to the default page
Response.Redirect "default.asp"

The page I uploaded this to is here:
http://www (dot) foremostgroups (dot) com/dev/2007corporate/default.asp

Can anyone fill me in on this guestbook.txt file? I would really like to know where this is coming from and how I can access it...

Thanks a lot,
Dan

gil davis
03-21-2008, 01:38 PM
I don't get this - where is this file?
It is on the server. However, if you don't actually own the server hardware, you probably don't have sufficient rights to actually put a file on the "c:" drive.

dtm32236
03-21-2008, 02:17 PM
we own the server... i never uploaded a guestbook.txt file though? was it created automatically?

yamaharuss
03-21-2008, 07:28 PM
You'll need to create a blank guestbook.txt file and upload it wherever on the server. Then change

MyFile = "c:\intepub\wwwroot\mydomain\dev\2007corporate\guestbook.txt"

.. or wherever it ends up locally.

You'll need to set write permissions on that file as well.

dtm32236
03-24-2008, 09:30 AM
thanks yamaharuss... i'll talk to the MIS team here and see if we can get this set up.

is there maybe a better way I should be doing this?

Basically, I have this page to look up local toilet rebate programs (http://www.foremostgroups.com/resources/national_toilet_rebate_program.html) and I want users to be able to discuss this, or post new links if they know of one we're missing. But I want a separate guestbook for each state. It seems like it's going to be a little complicated, so I thought I'd get some ideas - maybe there's a better way I could do this.

PS - we don't have PHP support.

yamaharuss
03-24-2008, 09:31 AM
You really need to use a database for that.

dtm32236
03-24-2008, 09:37 AM
wow - quick response!

oh boy - that sounds like fun (especially not knowing ASP very well).

I'll assume that I'd probably use ODBC and SQL? I hardly know where to begin. If you know of any good resources, would you send me a link or two? I'm a pretty quick learner, and the MIS team could probably help me out with this.

Thanks again yamaharuss.

dtm32236
03-25-2008, 11:17 AM
Okay, so I got this working the way I want (the simple way using the .txt files - I didn't want to get into databases, cause that would take too long to teach myself). Anyway, one more simple question:

I have the form execute, and it works perfectly:

<form method="post" action="write.asp">
<p><input type="hidden" name="state" value="AK"></p>
<p><label for="user_name">Name: </label><br><input name="user_name" type="text" size="35"><input type="text" name="info" alt="special" class="special"></p>
<p><label for="user_name">Comments: </label><br><textarea rows="3" cols="27" name="new_line" style="border:1px solid #ccc;"></textarea></p>
<p><input type="submit" value="Post Comment"></p>
</form>
<br>
<%
MyFile = "c:\alaska.txt"
'Opens the guestbook file if it exists
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
IF MyFileObj.FileExists(MyFile) THEN
Set MyTextFile=MyFileObj.OpenTextFile(MyFile)
'Reads a line, and outputs it
WHILE NOT MyTextFile.AtEndOfStream %>
<p class="post"><%=MyTextFile.ReadLine%></p>
<% WEND
'Closes the textfile
MyTextFile.Close
END IF' Does file exist
%>
<!-- JavaScript Code here -->

but now, I'd like it to trigger a JavaScript function afterwards. The function is "togLayer('AK'); return false". Does anyone know how I can make this execute (it's no onclick or anything, i'm hoping to make it automatic). Does that make sense?

Thanks a lot guys.

dtm32236
03-25-2008, 12:24 PM
nevermind...

<script type="text/javascript">
togLayer('AK');
</script>

worked just fine. everything works great!

thanks gil davis and yamaharuss for your help!