Results 1 to 5 of 5

Thread: ASP

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    15
    Hi, i was wondering if anyone could help me. I am a little new to vb, but have do alot with it.

    Can anyone tell me the most simplest way i can take user input from my web page (using asp or whatever) and post it into a text file on my hard drive. (keep in mind my comp. is the server running the web page.)

    I need some asp program to simply save user input, that is all.

  2. #2
    Guest
    Here is some nice examples from http://www.15seconds.com


    <html>
    <body background="/images/bground.gif" bgcolor="#ffffff" text="#000000" marginheight="0" topmargin="0">
    <form action="formhandler.asp" method="post">

    <input type="text" size="10" name="username">

    <input type="text" size="10" name="homepage">

    <input type="text" size="10" name="Email">

    </form>
    </body>
    </html>



    Let's look at the script in formhandler.asp that will handle the form:


    <%

    ' Get form info

    strName = Request.Form("username")

    strHomePage = Request.Form("homepage")

    strEmail = Request.Form("Email")



    ' create the fso object

    Set fso = Server.CreateObject("Scripting.FileSystemObject")


    So far, this should be nothing new. We take the form variables and assign them to variables for easier use later on. Now comes the fun part - writing the file:


    path = "c:\temp\test.txt"

    ForReading = 1, ForWriting = 2, ForAppending = 3

    ' open the file

    set file = fso.opentextfile(path, ForAppending, TRUE)


    ' write the info to the file

    file.write(strName) & vbcrlf

    file.write(strHomePage) & vbcrlf

    file.write(strEmail) & vbcrlf


    ' close and clean up

    file.close

    set file = nothing

    set fso = nothing

    Reading Files

    So now we have some nice user information stored in a file, which happily works as a simple database. Now suppose a user comes along and wants to view all your wonderful visitors. We've got to spit that information out somehow. Since we don't have a database with nicely structured columns, we'll have to get clever to output the results we want.

    We know that in the file we just created, the first line is the user's name, the second line is their homepage, and the third line is their email address. Every subsequent user who comes along will also have their information stored in this way, so that every third line will contain the same type of information. Knowing that, we can now write some code to grab the info:





    <%

    ' create the fso object

    set fso = Server.Createobject("Scripting.FileSystemObject")

    path = "c:\temp\test.txt"



    ' open the file

    set file = fso.opentextfile(path, 1) <-- For
    reading



    Now let's grab each line and format it accordingly:





    do until file.AtEndOfStream

    Response.write("Name: " & file.ReadLine & " ")

    Response.write("Home Page: " & file.ReadLine & " ")

    Response.write("Email: " & file.ReadLine & "<p>")

    loop



    ' close and clean up

    file.close

    set file = nothing

    set fso = nothing

    %>



  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    15
    Um, thanx, but it doesn't work. Are you sure that there isn't an mistake in the code. Can you check?
    I create a form with a submit button post it to the formhandler.asp and put the asp script into the formhandler.asp .

  4. #4
    Guest
    What error messages are you getting?

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    15
    thats just it, there is no error messages at all. it just doesn't right the file to my hard drive.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width