syntax error in replace statement

Ask a Question related to ASP, Design and Development.

  1. #1

    Default syntax error in replace statement

    What's wrong with this code?

    strLongDesc =
    Replace(Replace(Replace(Replace(Trim(Request.Form( "LongDesc")),"'","''"),vbC
    rLf,"<br>"),"<",&lt;),"<",&gt;)

    Background:
    This field is a textarea, and I needed to account for apostrophes, which I
    had already done, and replaced line breaks with html line breaks on my page
    which displays this stuff. That works fine. But then a user entered this
    line, pasted from a log file:
    SQL Statement: <SELECT * FROM etc., etc.

    Which resulted in an actual dropdown box being displayed, and all the rest
    of the description after that point was not displayed. So I tried to put in
    code to replace the < and > with a &lt; and &gt; and the code I get when the
    page loads is:

    Microsoft VBScript compilation (0x800A03EA)
    Syntax error
    /AddToTicket.asp, line 75, column 106
    strLongDesc =
    Replace(Replace(Replace(Replace(Trim(Request.Form( "LongDesc")),"'","''"),vbC
    rLf,"<br>"),"<",&lt;),"<",&gt;)
    ----------------------------------------------------------------------------
    -----------------------------^


    middletree Guest

  2. Similar Questions and Discussions

    1. Syntax error in UPDATE statement.
      ok i have an update form that i created it is for the admin of the site to add/edit user account info for memebers to login. the form adds or edits...
    2. Syntax error in INSERT INTO statement
      I have a two table setup in fact I am doing the blog tutorial on Macromedia but with Access and asp I have two tables topic and articles I have a...
    3. Syntax error in Where Statement
      Having a problem with what the server says is a syntax error in the Where statement, but cant figure out where it is. <cfif ...
    4. Syntax Error Update Statement
      Can someone tell me what's wrong with this code? I need help. Thanks! It is an update page. FIRST PAGE: LOGIN CHECK <!--- Filename: ...
    5. Syntax Error In Update Statement
      I'm having a problem getting one piece of code to work on my app. It's a simple password change. For some reason, I've been getting the following...
  3. #2

    Default Re: syntax error in replace statement

    Well, I found the problem with the syntax, but now it simply doesn't work.

    Here is my code:

    strLongDesc =
    Replace(Replace(Replace(Replace(Trim(Request.Form( "LongDesc")),"'","''"),vbC
    rLf,"<br>"),"<","&lt;"),">","&gt;")

    and of course, I insert strLongDesc into a field in SQL Server, and when I
    open it up in SQL Server, it still shows what I typed into the textarea,
    which is <select>, whereas I should see &lt;select&gt;

    What am I doing wrong?



    "middletree" <middletree@htomail.com> wrote in message
    news:OcP6PckmDHA.2732@TK2MSFTNGP11.phx.gbl...
    > What's wrong with this code?
    >
    > strLongDesc =
    >
    Replace(Replace(Replace(Replace(Trim(Request.Form( "LongDesc")),"'","''"),vbC
    > rLf,"<br>"),"<",&lt;),"<",&gt;)
    >
    > Background:
    > This field is a textarea, and I needed to account for apostrophes, which I
    > had already done, and replaced line breaks with html line breaks on my
    page
    > which displays this stuff. That works fine. But then a user entered this
    > line, pasted from a log file:
    > SQL Statement: <SELECT * FROM etc., etc.
    >
    > Which resulted in an actual dropdown box being displayed, and all the rest
    > of the description after that point was not displayed. So I tried to put
    in
    > code to replace the < and > with a &lt; and &gt; and the code I get when
    the
    > page loads is:
    >
    > Microsoft VBScript compilation (0x800A03EA)
    > Syntax error
    > /AddToTicket.asp, line 75, column 106
    > strLongDesc =
    >
    Replace(Replace(Replace(Replace(Trim(Request.Form( "LongDesc")),"'","''"),vbC
    > rLf,"<br>"),"<",&lt;),"<",&gt;)
    > --------------------------------------------------------------------------
    --
    > -----------------------------^
    >
    >

    middletree Guest

  4. #3

    Default Re: syntax error in replace statement

    (a) you need double quotes around "&lt;" and "&gt;"

    (b) how about:

    strLongDesc = trim(server.HTMLEncode(Request.Form("LongDesc")))
    strLongDesc = replace(replace(strLongDesc,"'","''"),VBCrLf,"<br> ")




    "middletree" <middletree@htomail.com> wrote in message
    news:OcP6PckmDHA.2732@TK2MSFTNGP11.phx.gbl...
    > What's wrong with this code?
    >
    > strLongDesc =
    >
    Replace(Replace(Replace(Replace(Trim(Request.Form( "LongDesc")),"'","''"),vbC
    > rLf,"<br>"),"<",&lt;),"<",&gt;)
    >
    > Background:
    > This field is a textarea, and I needed to account for apostrophes, which I
    > had already done, and replaced line breaks with html line breaks on my
    page
    > which displays this stuff. That works fine. But then a user entered this
    > line, pasted from a log file:
    > SQL Statement: <SELECT * FROM etc., etc.
    >
    > Which resulted in an actual dropdown box being displayed, and all the rest
    > of the description after that point was not displayed. So I tried to put
    in
    > code to replace the < and > with a &lt; and &gt; and the code I get when
    the
    > page loads is:
    >
    > Microsoft VBScript compilation (0x800A03EA)
    > Syntax error
    > /AddToTicket.asp, line 75, column 106
    > strLongDesc =
    >
    Replace(Replace(Replace(Replace(Trim(Request.Form( "LongDesc")),"'","''"),vbC
    > rLf,"<br>"),"<",&lt;),"<",&gt;)
    > --------------------------------------------------------------------------
    --
    > -----------------------------^
    >
    >

    Aaron Bertrand [MVP] Guest

  5. #4

    Default Re: syntax error in replace statement

    > when I open it up in SQL Server,

    Where in SQL Server? Don't use Enterprise Manager for viewing data (e.g.
    Return all rows). It is liable to do all sorts of funky things in order to
    present the data to you in a "friendly" way (for some other issues see
    [url]http://www.aspfaq.com/2455[/url]). Run a SELECT query in Query Analyzer. Also,
    response.write(sql) to make sure the replacements were done.

    Another piece of friendly advice: store the statement as is, and use
    Server.HTMLEncode when you *retrieve* and *display* it. HTML formatting has
    little use/place inside the database.


    Aaron Bertrand [MVP] Guest

  6. #5

    Default Re: syntax error in replace statement

    OK, I've not gotten familiar with HTMLEncode. That will take care of the <
    and other characters, then?

    I'll try it out. Thanks, very much.

    I also never knew that that you said about Enterprise Mgr vs. Query analyzer
    in the other post. thanks


    "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
    news:eVS8skkmDHA.964@TK2MSFTNGP10.phx.gbl...
    > (a) you need double quotes around "&lt;" and "&gt;"
    >
    > (b) how about:
    >
    > strLongDesc = trim(server.HTMLEncode(Request.Form("LongDesc")))
    > strLongDesc = replace(replace(strLongDesc,"'","''"),VBCrLf,"<br> ")
    >
    >
    >
    >
    > "middletree" <middletree@htomail.com> wrote in message
    > news:OcP6PckmDHA.2732@TK2MSFTNGP11.phx.gbl...
    > > What's wrong with this code?
    > >
    > > strLongDesc =
    > >
    >
    Replace(Replace(Replace(Replace(Trim(Request.Form( "LongDesc")),"'","''"),vbC
    > > rLf,"<br>"),"<",&lt;),"<",&gt;)
    > >
    > > Background:
    > > This field is a textarea, and I needed to account for apostrophes, which
    I
    > > had already done, and replaced line breaks with html line breaks on my
    > page
    > > which displays this stuff. That works fine. But then a user entered this
    > > line, pasted from a log file:
    > > SQL Statement: <SELECT * FROM etc., etc.
    > >
    > > Which resulted in an actual dropdown box being displayed, and all the
    rest
    > > of the description after that point was not displayed. So I tried to put
    > in
    > > code to replace the < and > with a &lt; and &gt; and the code I get when
    > the
    > > page loads is:
    > >
    > > Microsoft VBScript compilation (0x800A03EA)
    > > Syntax error
    > > /AddToTicket.asp, line 75, column 106
    > > strLongDesc =
    > >
    >
    Replace(Replace(Replace(Replace(Trim(Request.Form( "LongDesc")),"'","''"),vbC
    > > rLf,"<br>"),"<",&lt;),"<",&gt;)
    >
    > --------------------------------------------------------------------------
    > --
    > > -----------------------------^
    > >
    > >
    >
    >

    middletree Guest

  7. #6

    Default Re: syntax error in replace statement

    Well, I tried it exactly as you have it in (b) below, and it didn't work.
    Also tried it with double quotes around the &lt, and it still stored my text
    of <select> as <select>, which displayed as a dropdown.


    "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
    news:eVS8skkmDHA.964@TK2MSFTNGP10.phx.gbl...
    > (a) you need double quotes around "&lt;" and "&gt;"
    >
    > (b) how about:
    >
    > strLongDesc = trim(server.HTMLEncode(Request.Form("LongDesc")))
    > strLongDesc = replace(replace(strLongDesc,"'","''"),VBCrLf,"<br> ")
    >
    >
    >
    >
    > "middletree" <middletree@htomail.com> wrote in message
    > news:OcP6PckmDHA.2732@TK2MSFTNGP11.phx.gbl...
    > > What's wrong with this code?
    > >
    > > strLongDesc =
    > >
    >
    Replace(Replace(Replace(Replace(Trim(Request.Form( "LongDesc")),"'","''"),vbC
    > > rLf,"<br>"),"<",&lt;),"<",&gt;)
    > >
    > > Background:
    > > This field is a textarea, and I needed to account for apostrophes, which
    I
    > > had already done, and replaced line breaks with html line breaks on my
    > page
    > > which displays this stuff. That works fine. But then a user entered this
    > > line, pasted from a log file:
    > > SQL Statement: <SELECT * FROM etc., etc.
    > >
    > > Which resulted in an actual dropdown box being displayed, and all the
    rest
    > > of the description after that point was not displayed. So I tried to put
    > in
    > > code to replace the < and > with a &lt; and &gt; and the code I get when
    > the
    > > page loads is:
    > >
    > > Microsoft VBScript compilation (0x800A03EA)
    > > Syntax error
    > > /AddToTicket.asp, line 75, column 106
    > > strLongDesc =
    > >
    >
    Replace(Replace(Replace(Replace(Trim(Request.Form( "LongDesc")),"'","''"),vbC
    > > rLf,"<br>"),"<",&lt;),"<",&gt;)
    >
    > --------------------------------------------------------------------------
    > --
    > > -----------------------------^
    > >
    > >
    >
    >

    middletree Guest

  8. #7

    Default Re: syntax error in replace statement

    "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
    news:eg8cFokmDHA.988@TK2MSFTNGP10.phx.gbl...
    > > when I open it up in SQL Server,
    >
    > Where in SQL Server? Don't use Enterprise Manager for viewing data (e.g.
    > Return all rows). It is liable to do all sorts of funky things in order
    to
    > present the data to you in a "friendly" way (for some other issues see
    > [url]http://www.aspfaq.com/2455[/url]). Run a SELECT query in Query Analyzer. Also,
    > response.write(sql) to make sure the replacements were done.
    As it turned out, the Query A vs. Ent Mgr were both displying correctly, but
    I will make sure i view the data correctly from now on. But the problem is
    that the replace function is not working. I verified this per your
    suggestion with the response.write statement. It does just fine with the
    <br> and quotes. Very puzzling and frustrating

    >
    > Another piece of friendly advice: store the statement as is, and use
    > Server.HTMLEncode when you *retrieve* and *display* it. HTML formatting
    has
    > little use/place inside the database.
    >
    >

    middletree Guest

  9. #8

    Default Re: syntax error in replace statement

    Then my guess is there are no < or > characters for replacement? Compare
    this to the completed SQL statement:

    Response.write(request.form("whatever_the_variable _was"))




    "middletree" <middletree@htomail.com> wrote in message
    news:#SAj7$kmDHA.2424@TK2MSFTNGP10.phx.gbl...
    > "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
    > news:eg8cFokmDHA.988@TK2MSFTNGP10.phx.gbl...
    > > > when I open it up in SQL Server,
    > >
    > > Where in SQL Server? Don't use Enterprise Manager for viewing data
    (e.g.
    > > Return all rows). It is liable to do all sorts of funky things in order
    > to
    > > present the data to you in a "friendly" way (for some other issues see
    > > [url]http://www.aspfaq.com/2455[/url]). Run a SELECT query in Query Analyzer.
    Also,
    > > response.write(sql) to make sure the replacements were done.
    >
    > As it turned out, the Query A vs. Ent Mgr were both displying correctly,
    but
    > I will make sure i view the data correctly from now on. But the problem is
    > that the replace function is not working. I verified this per your
    > suggestion with the response.write statement. It does just fine with the
    > <br> and quotes. Very puzzling and frustrating
    >
    >
    > >
    > > Another piece of friendly advice: store the statement as is, and use
    > > Server.HTMLEncode when you *retrieve* and *display* it. HTML formatting
    > has
    > > little use/place inside the database.
    > >
    > >
    >
    >

    Aaron Bertrand [MVP] Guest

  10. #9

    Default Re: syntax error in replace statement

    Well, had typed:

    <select>

    into the textarea, and verified that this is what went in, both by
    response.write, and looking into SQL Server.




    "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
    news:utW7lClmDHA.2772@TK2MSFTNGP10.phx.gbl...
    > Then my guess is there are no < or > characters for replacement? Compare
    > this to the completed SQL statement:
    >
    > Response.write(request.form("whatever_the_variable _was"))
    >
    >
    >
    >
    > "middletree" <middletree@htomail.com> wrote in message
    > news:#SAj7$kmDHA.2424@TK2MSFTNGP10.phx.gbl...
    > > "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
    > > news:eg8cFokmDHA.988@TK2MSFTNGP10.phx.gbl...
    > > > > when I open it up in SQL Server,
    > > >
    > > > Where in SQL Server? Don't use Enterprise Manager for viewing data
    > (e.g.
    > > > Return all rows). It is liable to do all sorts of funky things in
    order
    > > to
    > > > present the data to you in a "friendly" way (for some other issues see
    > > > [url]http://www.aspfaq.com/2455[/url]). Run a SELECT query in Query Analyzer.
    > Also,
    > > > response.write(sql) to make sure the replacements were done.
    > >
    > > As it turned out, the Query A vs. Ent Mgr were both displying correctly,
    > but
    > > I will make sure i view the data correctly from now on. But the problem
    is
    > > that the replace function is not working. I verified this per your
    > > suggestion with the response.write statement. It does just fine with the
    > > <br> and quotes. Very puzzling and frustrating
    > >
    > >
    > > >
    > > > Another piece of friendly advice: store the statement as is, and use
    > > > Server.HTMLEncode when you *retrieve* and *display* it. HTML
    formatting
    > > has
    > > > little use/place inside the database.
    > > >
    > > >
    > >
    > >
    >
    >

    middletree Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139