ASP Newbie question

Discussion in 'ASP General' started by Manoj, Jan 12, 2005.

  1. Manoj

    Manoj Guest

    Good Afternoon,

    I have a a bit of a problem understanding the root of this problem (apart
    fromthe fact that I'm very new to this).

    I'm trying to learn ASP at the very basic level to start. I'm doing this
    from the IIS server documentation. There are a few ASP tutorials and I'm
    trying to follow them through.

    I'm on the introductory tutorial that teaches how to put information into an
    Access database that resides in the webserver folder (in my case,
    "C:\inetpub\wwwroot\LearningASP".

    The name of the database file is Guestbook.mdb.

    The only difference is that I had already created a subweb named
    "LearningASP" and the tutorial asks to create a subweb called "Tutorial".

    This is the code from the actual Tutorial File which I n:

    <%@ Language=VBScript %>

    <html>
    <head>
    <title>Guest Book Using Connection Object Only</title>
    </head>
    <body>
    <font face="arial">
    <h2>Guest Book Using Connection Object Only</h2>

    <%
    If Not Request.QueryString("Message") = "True" Then
    'No information has been input yet, so provide the form.
    %>
    <p>
    <FORM NAME="GuestBook1" METHOD="GET" ACTION="guestbook1.asp">
    <table>
    <tr>
    <td><font face="arial">From:</td><td><INPUT TYPE="TEXT" NAME="From"></td>
    </tr><tr>
    <td><font face="arial">E-mail Address:</td><td><INPUT TYPE="TEXT"
    NAME="EmailAdd"></td>
    </tr><tr>
    <td><font face="arial">CC:</td><td><INPUT TYPE="TEXT" NAME="CC"><td>
    </tr><tr>
    <td><font face="arial">Subject:</td><td><INPUT TYPE="TEXT"
    NAME="Subject"></td>
    </tr>
    </table>
    Message: <br><TEXTAREA NAME="Memo" ROWS=6 COLS=70></TEXTAREA>
    </p>

    <p>
    <INPUT TYPE="HIDDEN" NAME="Message" VALUE="TRUE">
    <INPUT TYPE="SUBMIT" VALUE="Submit Information">
    </FORM>
    </p>
    <%
    Else
    'The HIDDEN button above sets the Message variable to True.
    'We know now that the form data has been entered.

    'Get the data from the form. We will be inserting it into the database.
    'Access doesn't like some characters, such as single-quotes, so encode the
    ' data using the HTMLEncode method of the ASP Server object.
    dim strTB1, strTB2, strTB3, strTB4, strMB1, strCommand
    strTB1 = Server.HTMLEncode(Request.QueryString("From"))
    strTB2 = Server.HTMLEncode(Request.QueryString("EmailAdd"))
    strTB3 = Server.HTMLEncode(Request.QueryString("CC"))
    strTB4 = Server.HTMLEncode(Request.QueryString("Subject"))
    strMB1 = Server.HTMLEncode(Request.QueryString("Memo"))

    'This is a connection string. ADO uses it to connect to a database
    through the Access driver.
    'It needs the provider name of the Access driver and the name of the
    Access database.
    'Connection strings are slightly different, depending on the provided
    being used,
    ' but they all use semicolons to separate variables.
    'If this line causes and error, search in your registry for
    'Microsoft.JET to see if 4.0 is your version.
    strProvider = "Provider=Microsoft.JET.OLEDB.4.0;Data
    Source=C:\InetPub\Wwwroot\LearningASP\guestbook.mdb;"

    'This creates an instance of an ADO Connection object.
    'There are 4 other ADO objects available to you, each with different
    methods and
    'properties that allow you to do almost anything with database data.
    Set objConn = server.createobject("ADODB.Connection")

    'The Open method of the Connection object uses the connection string to
    ' create a connection to the database.
    objConn.Open strProvider

    'Define the query.
    'There are many types of queries, allowing you to add, remove, or get data.
    'This query will add your data into the database, using the INSERT INTO
    key words.
    'Here, Guestbook is the name of the table.
    'You need single-quotes around strings here.
    strCommand = "INSERT INTO Guestbook (FTB1,FTB2,FTB3,FTB4,FMB1) VALUES ('"
    strCommand = strCommand & strTB1 & "','" & strTB2 & "','" & strTB3 & "','"
    & strTB4 & "','" & strMB1
    strCommand = StrCommand & "')"

    'Execute the query to add the data into the database.
    objConn.Execute strCommand

    Response.Write("Thank you! Your data has been added.")

    End if
    %>

    </font>
    </body>
    </html>

    I copied and pasted it into a blank document after running into problems
    when I manually entered the code for the first file, "Guestbook1.asp". Here
    is the code from "Guestbook1.asp":

    <%@ Language=VBScript %>

    <html>
    <head>
    <title>Guest Book Using Connection Object Only</title>
    </head>
    <body>
    <font face="arial">
    <h2>Guest Book Using Connection Object Only</h2>

    <%
    If Not Request.QueryString("Message") = "True" Then
    'No information has been input yet, so provide the form.
    %>
    <p>
    <FORM NAME="GuestBook1" METHOD="GET" ACTION="guestbook1.asp">
    <table>
    <tr>
    <td><font face="arial">From:</td><td><INPUT TYPE="TEXT"

    NAME="From"></td>
    </tr><tr>
    <td><font face="arial">E-mail Address:</td><td><INPUT

    TYPE="TEXT" NAME="EmailAdd"></td>
    </tr><tr>
    <td><font face="arial">CC:</td><td><INPUT TYPE="TEXT"

    NAME="CC"><td>
    </tr><tr>
    <td><font face="arial">Subject:</td><td><INPUT TYPE="TEXT"

    NAME="Subject"></td>
    </tr>
    </table>
    Message: <br><TEXTAREA NAME="Memo" ROWS=6 COLS=70></TEXTAREA>
    </p>

    <p>
    <INPUT TYPE="HIDDEN" NAME="Message" VALUE="TRUE">
    <INPUT TYPE="SUBMIT" VALUE="Submit Information">
    </FORM>
    </p>
    <%
    Else
    'The HIDDEN button above sets the Message variable to True.
    'We know now that the form data has been entered.

    'Get the data from the form. We will be inserting it into

    the database.
    'Access doesn't like some characters, such as

    single-quotes, so encode the
    ' data using the HTMLEncode method of the ASP Server

    object.
    dim strTB1, strTB2, strTB3, strTB4, strMB1, strCommand
    strTB1 = Server.HTMLEncode(Request.QueryString("From"))
    strTB2 = Server.HTMLEncode(Request.QueryString("EmailAdd"))
    strTB3 = Server.HTMLEncode(Request.QueryString("CC"))
    strTB4 = Server.HTMLEncode(Request.QueryString("Subject"))
    strMB1 = Server.HTMLEncode(Request.QueryString("Memo"))

    'This is a connection string. ADO uses it to connect to a

    database through the Access driver.
    'It needs the provider name of the Access driver and the

    name of the Access database.
    'Connection strings are slightly different, depending on

    the provided being used,
    ' but they all use semicolons to separate variables.
    'If this line causes and error, search in your registry for
    'Microsoft.JET to see if 4.0 is your version.
    strProvider = "Provider=Microsoft.JET.OLEDB.4.0;Data

    Source=C:\InetPub\Wwwroot\LearningASP\guestbook.mdb;"

    'This creates an instance of an ADO Connection object.
    'There are 4 other ADO objects available to you, each with

    different methods and
    'properties that allow you to do almost anything with

    database data.
    Set objConn = server.createobject("ADODB.Connection")

    'The Open method of the Connection object uses the

    connection string to
    ' create a connection to the database.
    objConn.Open strProvider

    'Define the query.
    'There are many types of queries, allowing you to add,

    remove, or get data.
    'This query will add your data into the database, using the

    INSERT INTO key words.
    'Here, Guestbook is the name of the table.
    'You need single-quotes around strings here.
    strCommand = "INSERT INTO Guestbook

    (FTB1,FTB2,FTB3,FTB4,FMB1) VALUES ('"
    strCommand = strCommand & strTB1 & "','" & strTB2 & "','" &

    strTB3 & "','" & strTB4 & "','" & strMB1
    strCommand = StrCommand & "')"

    'Execute the query to add the data into the database.
    objConn.Execute strCommand

    Response.Write("Thank you! Your data has been added.")

    End if
    %>

    </font>
    </body>
    </html>

    Like I said I first manually typed up Guestbook1.asp and for some reason,
    the page would appear in IE, but after entering the fields, it wouldn't
    upload the data to the Access file.

    Opened another blank file and just copied and pasted the tutorial code into
    it and named it Guestboo11.asp and changed the references to match the file
    name as well as the location of the database and this one worled perfectly
    fine!

    I'm trying to understand where I went wrong. I tried to do a side-by-side
    comparison without any luck.

    Any advise or information for a poor sod trying to learning this stuff?

    Thanks!

    Manoj
     
    Manoj, Jan 12, 2005
    #1
    1. Advertising

  2. Manoj

    Roland Hall Guest

    "Manoj" wrote in message
    news:...

    : I have a a bit of a problem understanding the root of this problem (apart
    : fromthe fact that I'm very new to this).
    :
    : I'm trying to learn ASP at the very basic level to start. I'm doing this
    : from the IIS server documentation. There are a few ASP tutorials and I'm
    : trying to follow them through.
    :
    : I'm on the introductory tutorial that teaches how to put information into
    an
    : Access database that resides in the webserver folder (in my case,
    : "C:\inetpub\wwwroot\LearningASP".
    :
    : The name of the database file is Guestbook.mdb.
    :
    : The only difference is that I had already created a subweb named
    : "LearningASP" and the tutorial asks to create a subweb called "Tutorial".
    :
    : This is the code from the actual Tutorial File which I n:
    :
    : <%@ Language=VBScript %>
    :
    : <html>
    : <head>
    : <title>Guest Book Using Connection Object Only</title>
    : </head>
    : <body>
    : <font face="arial">
    : <h2>Guest Book Using Connection Object Only</h2>
    :
    : <%
    : If Not Request.QueryString("Message") = "True" Then
    : 'No information has been input yet, so provide the form.
    : %>
    : <p>
    : <FORM NAME="GuestBook1" METHOD="GET" ACTION="guestbook1.asp">
    : <table>
    : <tr>
    : <td><font face="arial">From:</td><td><INPUT TYPE="TEXT" NAME="From"></td>
    : </tr><tr>
    : <td><font face="arial">E-mail Address:</td><td><INPUT TYPE="TEXT"
    : NAME="EmailAdd"></td>
    : </tr><tr>
    : <td><font face="arial">CC:</td><td><INPUT TYPE="TEXT" NAME="CC"><td>
    : </tr><tr>
    : <td><font face="arial">Subject:</td><td><INPUT TYPE="TEXT"
    : NAME="Subject"></td>
    : </tr>
    : </table>
    : Message: <br><TEXTAREA NAME="Memo" ROWS=6 COLS=70></TEXTAREA>
    : </p>
    :
    : <p>
    : <INPUT TYPE="HIDDEN" NAME="Message" VALUE="TRUE">
    : <INPUT TYPE="SUBMIT" VALUE="Submit Information">
    : </FORM>
    : </p>
    : <%
    : Else
    : 'The HIDDEN button above sets the Message variable to True.
    : 'We know now that the form data has been entered.
    :
    : 'Get the data from the form. We will be inserting it into the database.
    : 'Access doesn't like some characters, such as single-quotes, so encode the
    : ' data using the HTMLEncode method of the ASP Server object.
    : dim strTB1, strTB2, strTB3, strTB4, strMB1, strCommand
    : strTB1 = Server.HTMLEncode(Request.QueryString("From"))
    : strTB2 = Server.HTMLEncode(Request.QueryString("EmailAdd"))
    : strTB3 = Server.HTMLEncode(Request.QueryString("CC"))
    : strTB4 = Server.HTMLEncode(Request.QueryString("Subject"))
    : strMB1 = Server.HTMLEncode(Request.QueryString("Memo"))
    :
    : 'This is a connection string. ADO uses it to connect to a database
    : through the Access driver.
    : 'It needs the provider name of the Access driver and the name of the
    : Access database.
    : 'Connection strings are slightly different, depending on the provided
    : being used,
    : ' but they all use semicolons to separate variables.
    : 'If this line causes and error, search in your registry for
    : 'Microsoft.JET to see if 4.0 is your version.
    : strProvider = "Provider=Microsoft.JET.OLEDB.4.0;Data
    : Source=C:\InetPub\Wwwroot\LearningASP\guestbook.mdb;"
    :
    : 'This creates an instance of an ADO Connection object.
    : 'There are 4 other ADO objects available to you, each with different
    : methods and
    : 'properties that allow you to do almost anything with database data.
    : Set objConn = server.createobject("ADODB.Connection")
    :
    : 'The Open method of the Connection object uses the connection string to
    : ' create a connection to the database.
    : objConn.Open strProvider
    :
    : 'Define the query.
    : 'There are many types of queries, allowing you to add, remove, or get
    data.
    : 'This query will add your data into the database, using the INSERT INTO
    : key words.
    : 'Here, Guestbook is the name of the table.
    : 'You need single-quotes around strings here.
    : strCommand = "INSERT INTO Guestbook (FTB1,FTB2,FTB3,FTB4,FMB1) VALUES ('"
    : strCommand = strCommand & strTB1 & "','" & strTB2 & "','" & strTB3 & "','"
    : & strTB4 & "','" & strMB1
    : strCommand = StrCommand & "')"
    :
    : 'Execute the query to add the data into the database.
    : objConn.Execute strCommand
    :
    : Response.Write("Thank you! Your data has been added.")
    :
    : End if
    : %>
    :
    : </font>
    : </body>
    : </html>
    :
    : I copied and pasted it into a blank document after running into problems
    : when I manually entered the code for the first file, "Guestbook1.asp".
    Here
    : is the code from "Guestbook1.asp":
    :
    : <%@ Language=VBScript %>
    :
    : <html>
    : <head>
    : <title>Guest Book Using Connection Object Only</title>
    : </head>
    : <body>
    : <font face="arial">
    : <h2>Guest Book Using Connection Object Only</h2>
    :
    : <%
    : If Not Request.QueryString("Message") = "True" Then
    : 'No information has been input yet, so provide the form.
    : %>
    : <p>
    : <FORM NAME="GuestBook1" METHOD="GET" ACTION="guestbook1.asp">
    : <table>
    : <tr>
    : <td><font face="arial">From:</td><td><INPUT TYPE="TEXT"
    :
    : NAME="From"></td>
    : </tr><tr>
    : <td><font face="arial">E-mail Address:</td><td><INPUT
    :
    : TYPE="TEXT" NAME="EmailAdd"></td>
    : </tr><tr>
    : <td><font face="arial">CC:</td><td><INPUT TYPE="TEXT"
    :
    : NAME="CC"><td>
    : </tr><tr>
    : <td><font face="arial">Subject:</td><td><INPUT TYPE="TEXT"
    :
    : NAME="Subject"></td>
    : </tr>
    : </table>
    : Message: <br><TEXTAREA NAME="Memo" ROWS=6 COLS=70></TEXTAREA>
    : </p>
    :
    : <p>
    : <INPUT TYPE="HIDDEN" NAME="Message" VALUE="TRUE">
    : <INPUT TYPE="SUBMIT" VALUE="Submit Information">
    : </FORM>
    : </p>
    : <%
    : Else
    : 'The HIDDEN button above sets the Message variable to True.
    : 'We know now that the form data has been entered.
    :
    : 'Get the data from the form. We will be inserting it into
    :
    : the database.
    : 'Access doesn't like some characters, such as
    :
    : single-quotes, so encode the
    : ' data using the HTMLEncode method of the ASP Server
    :
    : object.
    : dim strTB1, strTB2, strTB3, strTB4, strMB1, strCommand
    : strTB1 = Server.HTMLEncode(Request.QueryString("From"))
    : strTB2 = Server.HTMLEncode(Request.QueryString("EmailAdd"))
    : strTB3 = Server.HTMLEncode(Request.QueryString("CC"))
    : strTB4 = Server.HTMLEncode(Request.QueryString("Subject"))
    : strMB1 = Server.HTMLEncode(Request.QueryString("Memo"))
    :
    : 'This is a connection string. ADO uses it to connect to a
    :
    : database through the Access driver.
    : 'It needs the provider name of the Access driver and the
    :
    : name of the Access database.
    : 'Connection strings are slightly different, depending on
    :
    : the provided being used,
    : ' but they all use semicolons to separate variables.
    : 'If this line causes and error, search in your registry for
    : 'Microsoft.JET to see if 4.0 is your version.
    : strProvider = "Provider=Microsoft.JET.OLEDB.4.0;Data
    :
    : Source=C:\InetPub\Wwwroot\LearningASP\guestbook.mdb;"
    :
    : 'This creates an instance of an ADO Connection object.
    : 'There are 4 other ADO objects available to you, each with
    :
    : different methods and
    : 'properties that allow you to do almost anything with
    :
    : database data.
    : Set objConn = server.createobject("ADODB.Connection")
    :
    : 'The Open method of the Connection object uses the
    :
    : connection string to
    : ' create a connection to the database.
    : objConn.Open strProvider
    :
    : 'Define the query.
    : 'There are many types of queries, allowing you to add,
    :
    : remove, or get data.
    : 'This query will add your data into the database, using the
    :
    : INSERT INTO key words.
    : 'Here, Guestbook is the name of the table.
    : 'You need single-quotes around strings here.
    : strCommand = "INSERT INTO Guestbook
    :
    : (FTB1,FTB2,FTB3,FTB4,FMB1) VALUES ('"
    : strCommand = strCommand & strTB1 & "','" & strTB2 & "','" &
    :
    : strTB3 & "','" & strTB4 & "','" & strMB1
    : strCommand = StrCommand & "')"
    :
    : 'Execute the query to add the data into the database.
    : objConn.Execute strCommand
    :
    : Response.Write("Thank you! Your data has been added.")
    :
    : End if
    : %>
    :
    : </font>
    : </body>
    : </html>
    :
    : Like I said I first manually typed up Guestbook1.asp and for some reason,
    : the page would appear in IE, but after entering the fields, it wouldn't
    : upload the data to the Access file.
    :
    : Opened another blank file and just copied and pasted the tutorial code
    into
    : it and named it Guestboo11.asp and changed the references to match the
    file
    : name as well as the location of the database and this one worled perfectly
    : fine!
    :
    : I'm trying to understand where I went wrong. I tried to do a side-by-side
    : comparison without any luck.
    :
    : Any advise or information for a poor sod trying to learning this stuff?

    It helps when you provide the error you receive rather than asking us to
    peruse your code to find an error which may be a single character.

    ASP errors generally give you the line number in the source document where
    the error occurred. When posting to a database, it's a good idea to write
    your SQL statement to the page so it is easier to check for typos (errors).

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Jan 13, 2005
    #2
    1. Advertising

  3. Manoj

    CJM Guest

    "Roland Hall" <nobody@nowhere> wrote in message
    news:ubUY11T%...
    > "Manoj" wrote in message
    > news:...


    [snip]

    > : Any advise or information for a poor sod trying to learning this stuff?
    >
    > It helps when you provide the error you receive rather than asking us to
    > peruse your code to find an error which may be a single character.
    >
    > ASP errors generally give you the line number in the source document where
    > the error occurred. When posting to a database, it's a good idea to write
    > your SQL statement to the page so it is easier to check for typos
    > (errors).
    >
    > --
    > Roland Hall


    I'm not being funny Roland, but couldn't you have snipped his post a bit..
    or top-posted..? :)
     
    CJM, Jan 13, 2005
    #3
  4. Manoj

    Roland Hall Guest

    "CJM" wrote in message news:%235LIrIV%...
    :
    : "Roland Hall" <nobody@nowhere> wrote in message
    : news:ubUY11T%...
    : > "Manoj" wrote in message
    : > news:...
    :
    : [snip]
    :
    :
    : I'm not being funny Roland, but couldn't you have snipped his post a bit..
    : or top-posted..? :)

    Well, I could have snipped his post a bit but I doubt I could have brought
    myself to top-post.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Jan 13, 2005
    #4
  5. Manoj

    Manoj Guest

    Gents,

    First, sorry about the long post. Can you tell I'm really new.

    Second, thanks for reply.

    Finally, in response to Roland's original reponse. Unfortunately, I'm not
    getting a page that reports an error. The only thing that's happening is it
    I get returned to the original page (the form where I input the information).
    In the Cut and Past version, an ackowledgement page is displayed after
    submitting the form (that's guestbook11.asp)

    In when I submit the form in guestbook1.asp basically nothing happens.

    Regards and thanks!

    Manoj

    "Roland Hall" wrote:

    > "CJM" wrote in message news:%235LIrIV%...
    > :
    > : "Roland Hall" <nobody@nowhere> wrote in message
    > : news:ubUY11T%...
    > : > "Manoj" wrote in message
    > : > news:...
    > :
    > : [snip]
    > :
    > :
    > : I'm not being funny Roland, but couldn't you have snipped his post a bit..
    > : or top-posted..? :)
    >
    > Well, I could have snipped his post a bit but I doubt I could have brought
    > myself to top-post.
    >
    > --
    > Roland Hall
    > /* This information is distributed in the hope that it will be useful, but
    > without any warranty; without even the implied warranty of merchantability
    > or fitness for a particular purpose. */
    > Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    > WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    > MSDN Library - http://msdn.microsoft.com/library/default.asp
    >
    >
    >
     
    Manoj, Jan 13, 2005
    #5
  6. Manoj

    Roland Hall Guest

    "Manoj" wrote in message
    news:...
    : First, sorry about the long post. Can you tell I'm really new.

    In your defense, if you don't know where the error is, how are you supposed
    to know which part of the code to show?


    : Second, thanks for reply.

    Np.

    : Finally, in response to Roland's original reponse. Unfortunately, I'm not
    : getting a page that reports an error. The only thing that's happening is
    it
    : I get returned to the original page (the form where I input the
    information).
    : In the Cut and Past version, an ackowledgement page is displayed after
    : submitting the form (that's guestbook11.asp)
    :
    : In when I submit the form in guestbook1.asp basically nothing happens.

    Both of those showed guestbook1.asp. Which is guestbook11.asp?

    I also saw that there is a test for "True" but what is submitted it the form
    element variable Message is being submitted as "TRUE".

    If Not Request.QueryString("Message") = "True" Then
    ..
    ..
    ..
    <INPUT TYPE="HIDDEN" NAME="Message" VALUE="TRUE">

    This is not a boolean and a test could have been:

    dim message
    if Request.QueryString("Message") <> "" Then

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Jan 13, 2005
    #6
  7. Manoj

    Morris Guest

    Manoj wrote:
    > Good Afternoon,
    >
    > I have a a bit of a problem understanding the root of this problem (apart
    > fromthe fact that I'm very new to this).
    >
    > I'm trying to learn ASP at the very basic level to start. I'm doing this
    > from the IIS server documentation. There are a few ASP tutorials and I'm
    > trying to follow them through.
    >
    > I'm on the introductory tutorial that teaches how to put information into an
    > Access database that resides in the webserver folder (in my case,
    > "C:\inetpub\wwwroot\LearningASP".
    >
    > The name of the database file is Guestbook.mdb.
    >
    > The only difference is that I had already created a subweb named
    > "LearningASP" and the tutorial asks to create a subweb called "Tutorial".
    >
    > This is the code from the actual Tutorial File which I n:
    >
    > <%@ Language=VBScript %>
    >
    > <html>
    > <head>
    > <title>Guest Book Using Connection Object Only</title>
    > </head>
    > <body>
    > <font face="arial">
    > <h2>Guest Book Using Connection Object Only</h2>
    >
    > <%
    > If Not Request.QueryString("Message") = "True" Then
    > 'No information has been input yet, so provide the form.
    > %>
    > <p>
    > <FORM NAME="GuestBook1" METHOD="GET" ACTION="guestbook1.asp">
    > <table>
    > <tr>
    > <td><font face="arial">From:</td><td><INPUT TYPE="TEXT" NAME="From"></td>
    > </tr><tr>
    > <td><font face="arial">E-mail Address:</td><td><INPUT TYPE="TEXT"
    > NAME="EmailAdd"></td>
    > </tr><tr>
    > <td><font face="arial">CC:</td><td><INPUT TYPE="TEXT" NAME="CC"><td>
    > </tr><tr>
    > <td><font face="arial">Subject:</td><td><INPUT TYPE="TEXT"
    > NAME="Subject"></td>
    > </tr>
    > </table>
    > Message: <br><TEXTAREA NAME="Memo" ROWS=6 COLS=70></TEXTAREA>
    > </p>
    >
    > <p>
    > <INPUT TYPE="HIDDEN" NAME="Message" VALUE="TRUE">
    > <INPUT TYPE="SUBMIT" VALUE="Submit Information">
    > </FORM>
    > </p>
    > <%
    > Else
    > 'The HIDDEN button above sets the Message variable to True.
    > 'We know now that the form data has been entered.
    >
    > 'Get the data from the form. We will be inserting it into the database.
    > 'Access doesn't like some characters, such as single-quotes, so encode the
    > ' data using the HTMLEncode method of the ASP Server object.
    > dim strTB1, strTB2, strTB3, strTB4, strMB1, strCommand
    > strTB1 = Server.HTMLEncode(Request.QueryString("From"))
    > strTB2 = Server.HTMLEncode(Request.QueryString("EmailAdd"))
    > strTB3 = Server.HTMLEncode(Request.QueryString("CC"))
    > strTB4 = Server.HTMLEncode(Request.QueryString("Subject"))
    > strMB1 = Server.HTMLEncode(Request.QueryString("Memo"))
    >
    > 'This is a connection string. ADO uses it to connect to a database
    > through the Access driver.
    > 'It needs the provider name of the Access driver and the name of the
    > Access database.
    > 'Connection strings are slightly different, depending on the provided
    > being used,
    > ' but they all use semicolons to separate variables.
    > 'If this line causes and error, search in your registry for
    > 'Microsoft.JET to see if 4.0 is your version.
    > strProvider = "Provider=Microsoft.JET.OLEDB.4.0;Data
    > Source=C:\InetPub\Wwwroot\LearningASP\guestbook.mdb;"
    >
    > 'This creates an instance of an ADO Connection object.
    > 'There are 4 other ADO objects available to you, each with different
    > methods and
    > 'properties that allow you to do almost anything with database data.
    > Set objConn = server.createobject("ADODB.Connection")
    >
    > 'The Open method of the Connection object uses the connection string to
    > ' create a connection to the database.
    > objConn.Open strProvider
    >
    > 'Define the query.
    > 'There are many types of queries, allowing you to add, remove, or get data.
    > 'This query will add your data into the database, using the INSERT INTO
    > key words.
    > 'Here, Guestbook is the name of the table.
    > 'You need single-quotes around strings here.
    > strCommand = "INSERT INTO Guestbook (FTB1,FTB2,FTB3,FTB4,FMB1) VALUES ('"
    > strCommand = strCommand & strTB1 & "','" & strTB2 & "','" & strTB3 & "','"
    > & strTB4 & "','" & strMB1
    > strCommand = StrCommand & "')"
    >
    > 'Execute the query to add the data into the database.
    > objConn.Execute strCommand
    >
    > Response.Write("Thank you! Your data has been added.")
    >
    > End if
    > %>
    >
    > </font>
    > </body>
    > </html>
    >


    <snip>

    >
    > Any advise or information for a poor sod trying to learning this stuff?
    >
    > Thanks!
    >
    > Manoj


    The error is being caused by the case of TRUE in the querystring. Your
    first line of VBScript is:

    If Not Request.QueryString("Message") = "True" Then....

    where the case of the word True is in proper case. However, in the
    hidden form field, its in uppercase:

    <INPUT TYPE="HIDDEN" NAME="Message" VALUE="TRUE">
    When the value is passed to the querystring, it is an an uppercase word,
    whereas your test is looking for something else (proper case), so
    Request.Querystring("Message") will never evaluate to "True", only
    "TRUE" or nothing. consequently, none of the code inserting the
    comments into the database will work.

    Change the hidden form element's value to "True" (as opposed to
    "TRUE")and have another go.

    Stick with it :)

    Morris
     
    Morris, Jan 13, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry C.
    Replies:
    8
    Views:
    276
    Uri Guttman
    Nov 23, 2003
  2. Kruno Saho
    Replies:
    0
    Views:
    168
    Kruno Saho
    Apr 7, 2013
  3. Dave Angel
    Replies:
    0
    Views:
    145
    Dave Angel
    Apr 7, 2013
  4. rusi
    Replies:
    0
    Views:
    131
  5. Miki Tebeka
    Replies:
    0
    Views:
    95
    Miki Tebeka
    Apr 7, 2013
Loading...

Share This Page