Connecting Tech Pros Worldwide Help | Site Map

help me with " sign in display of data in asp form

cooldv
Guest
 
Posts: n/a
#1: Jul 19 '05
i know how to replace the sign " when SUBMITTING a form in asp by this
code:
message = Replace(usermessage, "'", "''").

My problem is DISPLAYING data in an asp FORM, from an an access
database, when the data already contains a " sign

problem is like this:
access database .... to update on the internet .... a *dataupdate.asp*
page ..... On this page, the data gets displayed in a form where i
make corrections and then i update it ..... working perfectly; the
data gets displayed in the form perfectly well and gets updated also[color=blue][color=green][color=darkred]
>>> BUT >>>
>>> PROBLEM >>>[/color][/color][/color]
If there is a " sign in the data, then all the text beyond the " sign
is not displayed inside the text box of the form and is obviously lost
if the form is submitted to update the database.

Also, if data is like this:
text1 " text2 > text3 text4

then,
text1 is displayed inside the text box of the form
text2 is not displayed anywhere as it is after the sign "
the data beyond the > sign gets displayed, but
text3 text4 get displayed OUTSIDE the text box of the form as html
output


Here is the code:

<%
Actionvar=Request.QueryString("actionvar")

Set conn = server.createobject("adodb.connection")
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & server.mappath("database.mdb")
conn.Open DSNtemp

IF Actionvar="update" THEN
IF Len(TRIM(Request.Form("flag"))) = 0 THEN
SQLstmt = "SELECT * FROM database WHERE dataID=" &
Request.QueryString("Recid")

Set rs = conn.Execute(SQLstmt)
IF NOT RS.EOF THEN
%>

<table>
<FORM METHOD="post" ACTION="dataupdate.asp?Actionvar=update">
<INPUT TYPE="text" size="78" NAME="dataMessage"
VALUE="<%=rs("Message")%>">

<INPUT TYPE="hidden" NAME="flag" VALUE="2">
<INPUT TYPE="hidden" NAME="Recordid" VALUE="<%=rs("dataID")%>">
<INPUT TYPE="submit" VALUE="Update">
</form>
</table>

<%
rs.MoveNext
rs.Close
END IF
ELSEIF Request.Form("flag")="2" THEN
comnt = request.form("dataMessage")
kament = Replace(comnt, "'", "''")

SQLstmt = "UPDATE database SET "
SQLstmt = SQLstmt & "Message='" & kament & "' "

any help please???

i believe the problem is in how i am displaying data in this part of
the code:
<INPUT TYPE="hidden" NAME="Recordid" VALUE="<%=rs("dataID")%>">
Steven Burn
Guest
 
Posts: n/a
#2: Jul 19 '05

re: help me with " sign in display of data in asp form


You'll need to replace the quotes before they reach the database, using
something along the lines of;

Saving data;

yourdata = Request.Form("datamessage")
'// Replace quotes with: --
strData = Replace(yourdata, chr(34), "--")

Getting data;
'// replace -- with quotes
strData = Replace(yourdata, "--", chr(34))

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)


cooldv <mddv@hotmail.com> wrote in message
news:d356c6c0.0401180906.e14520e@posting.google.co m...[color=blue]
> i know how to replace the sign " when SUBMITTING a form in asp by this
> code:
> message = Replace(usermessage, "'", "''").
>
> My problem is DISPLAYING data in an asp FORM, from an an access
> database, when the data already contains a " sign
>
> problem is like this:
> access database .... to update on the internet .... a *dataupdate.asp*
> page ..... On this page, the data gets displayed in a form where i
> make corrections and then i update it ..... working perfectly; the
> data gets displayed in the form perfectly well and gets updated also[color=green][color=darkred]
> >>> BUT >>>
> >>> PROBLEM >>>[/color][/color]
> If there is a " sign in the data, then all the text beyond the " sign
> is not displayed inside the text box of the form and is obviously lost
> if the form is submitted to update the database.
>
> Also, if data is like this:
> text1 " text2 > text3 text4
>
> then,
> text1 is displayed inside the text box of the form
> text2 is not displayed anywhere as it is after the sign "
> the data beyond the > sign gets displayed, but
> text3 text4 get displayed OUTSIDE the text box of the form as html
> output
>
>
> Here is the code:
>
> <%
> Actionvar=Request.QueryString("actionvar")
>
> Set conn = server.createobject("adodb.connection")
> DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
> DSNtemp=dsntemp & "DBQ=" & server.mappath("database.mdb")
> conn.Open DSNtemp
>
> IF Actionvar="update" THEN
> IF Len(TRIM(Request.Form("flag"))) = 0 THEN
> SQLstmt = "SELECT * FROM database WHERE dataID=" &
> Request.QueryString("Recid")
>
> Set rs = conn.Execute(SQLstmt)
> IF NOT RS.EOF THEN
> %>
>
> <table>
> <FORM METHOD="post" ACTION="dataupdate.asp?Actionvar=update">
> <INPUT TYPE="text" size="78" NAME="dataMessage"
> VALUE="<%=rs("Message")%>">
>
> <INPUT TYPE="hidden" NAME="flag" VALUE="2">
> <INPUT TYPE="hidden" NAME="Recordid" VALUE="<%=rs("dataID")%>">
> <INPUT TYPE="submit" VALUE="Update">
> </form>
> </table>
>
> <%
> rs.MoveNext
> rs.Close
> END IF
> ELSEIF Request.Form("flag")="2" THEN
> comnt = request.form("dataMessage")
> kament = Replace(comnt, "'", "''")
>
> SQLstmt = "UPDATE database SET "
> SQLstmt = SQLstmt & "Message='" & kament & "' "
>
> any help please???
>
> i believe the problem is in how i am displaying data in this part of
> the code:
> <INPUT TYPE="hidden" NAME="Recordid" VALUE="<%=rs("dataID")%>">[/color]


Bob Barrows
Guest
 
Posts: n/a
#3: Jul 19 '05

re: help me with " sign in display of data in asp form


cooldv wrote:
<snip>
This
[color=blue]
> <INPUT TYPE="hidden" NAME="Recordid" VALUE="<%=rs("dataID")%>">[/color]

should be either this:

<INPUT TYPE="hidden" NAME="Recordid" VALUE='<%=rs("dataID")%>'>

or this:

<INPUT TYPE="hidden" NAME="Recordid" VALUE=
"<%=HTMLEncode(rs("dataID"))%>">

Check out this short example to see the difference:

<%
sText="text containing "" character"
Response.Write stext & "<BR>"
%>
<HTML>
<BODY>
<INPUT VALUE=" <%=server.HTMLEncode(sText)%>" style="WIDTH:345px">
</BODY>
</HTML>

HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Aaron Bertrand [MVP]
Guest
 
Posts: n/a
#4: Jul 19 '05

re: help me with " sign in display of data in asp form


> You'll need to replace the quotes before they reach the database, using[color=blue]
> something along the lines of;
>
> Saving data;
>
> yourdata = Request.Form("datamessage")[/color]

Too late at that point. The problem isn't putting the data into the
database, it's that the data is truncated (by having value="foo"bar") before
it even gets to the ASP form handler.
[color=blue]
> Getting data;
> '// replace -- with quotes
> strData = Replace(yourdata, "--", chr(34))[/color]

Plus, I disagree with this method altogether. Why would you replace quotes
with dashes? You're completely changing the meaning of the existing data,
plus you'll turn *ALL* dashes into double quotes when retrieving.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


Steven Burn
Guest
 
Posts: n/a
#5: Jul 19 '05

re: help me with " sign in display of data in asp form


Aaron Bertrand [MVP] <aaron@TRASHaspfaq.com> wrote in message
news:OKGk67e3DHA.2060@TK2MSFTNGP10.phx.gbl...[color=blue][color=green]
> > You'll need to replace the quotes before they reach the database, using
> > something along the lines of;
> >
> > Saving data;
> >
> > yourdata = Request.Form("datamessage")[/color]
>
> Too late at that point. The problem isn't putting the data into the
> database, it's that the data is truncated (by having value="foo"bar")[/color]
before[color=blue]
> it even gets to the ASP form handler.[/color]
</snip>

In that case, couldn't you use some javascript code or something?

<snip>[color=blue][color=green]
> > Getting data;
> > '// replace -- with quotes
> > strData = Replace(yourdata, "--", chr(34))[/color]
>
> Plus, I disagree with this method altogether. Why would you replace[/color]
quotes[color=blue]
> with dashes? You're completely changing the meaning of the existing data,
> plus you'll turn *ALL* dashes into double quotes when retrieving.[/color]
</snip>

I just figured you could replace the quotes with something thats not likely
to be in there (doesn't have to be dashes obviously), so if you don't want
to use dashes, you could replace it with &quote or something?

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)


Aaron Bertrand [MVP]
Guest
 
Posts: n/a
#6: Jul 19 '05

re: help me with " sign in display of data in asp form


> I just figured you could replace the quotes with something thats not
likely[color=blue]
> to be in there (doesn't have to be dashes obviously), so if you don't want
> to use dashes, you could replace it with &quote or something?[/color]

Again, the problem isn't in STORING the data. So a solution that involves
"encoding" the character to store in the database not only "vandalizes" the
data (someone running a SELECT column FROM table might not be aware of this
replace, and wonder why there's a dash or a tilde or some other character
when there should be a quote), it doesn't solve the issue anyway.


Chris Hohmann
Guest
 
Posts: n/a
#7: Jul 19 '05

re: help me with " sign in display of data in asp form


"Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
news:eTU0Pke3DHA.2428@tk2msftngp13.phx.gbl...[color=blue]
> cooldv wrote:
> <snip>
> This
>[color=green]
> > <INPUT TYPE="hidden" NAME="Recordid" VALUE="<%=rs("dataID")%>">[/color]
>
> should be either this:
>
> <INPUT TYPE="hidden" NAME="Recordid" VALUE='<%=rs("dataID")%>'>
>
> or this:
>
> <INPUT TYPE="hidden" NAME="Recordid" VALUE=
> "<%=HTMLEncode(rs("dataID"))%>">
>
> Check out this short example to see the difference:
>
> <%
> sText="text containing "" character"
> Response.Write stext & "<BR>"
> %>
> <HTML>
> <BODY>
> <INPUT VALUE=" <%=server.HTMLEncode(sText)%>" style="WIDTH:345px">
> </BODY>
> </HTML>[/color]

I'd like to vote for option 2, since it is immune to both apostrophes
( ' ) and quotes ( " ), as well any other entity references that may
exist in the data (less-than, greater-than, ampersand, etc...)


cooldv
Guest
 
Posts: n/a
#8: Jul 19 '05

re: help me with " sign in display of data in asp form


"Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message news:<eTU0Pke3DHA.2428@tk2msftngp13.phx.gbl>...[color=blue]
> cooldv wrote:
> <snip>
> This
>[color=green]
> > <INPUT TYPE="hidden" NAME="Recordid" VALUE="<%=rs("dataID")%>">[/color]
>
> should be either this:
>
> <INPUT TYPE="hidden" NAME="Recordid" VALUE='<%=rs("dataID")%>'>[/color]


-------- No!!!! with this change, any text beyond an apostrophe '
sign in the data disappears

[color=blue]
> or this:
>
> <INPUT TYPE="hidden" NAME="Recordid" VALUE=
> "<%=HTMLEncode(rs("dataID"))%>">
>
> Check out this short example to see the difference:
>
> <%
> sText="text containing "" character"
> Response.Write stext & "<BR>"
> %>
> <HTML>
> <BODY>
> <INPUT VALUE=" <%=server.HTMLEncode(sText)%>" style="WIDTH:345px">
> </BODY>
> </HTML>
>
> HTH,
> Bob Barrows[/color]

i could not understand what you meant by this. could you please be
more specific, how do i do that?
dataID or RecID is a numeric value and i have no trouble with the ID.
It is the TEXT with a double quote that is giving me hard time.

i put a demo of the problem here:
http://www.dv.pgims.org/datadisplay.asp

here is my code again:

<%
Actionvar=Request.QueryString("actionvar")

Set conn = server.createobject("adodb.connection")
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & server.mappath("database.mdb")
conn.Open DSNtemp

IF Actionvar="update" THEN
IF Len(TRIM(Request.Form("flag"))) = 0 THEN
SQLstmt = "SELECT * FROM database WHERE dataID=" &
Request.QueryString("Recid")

Set rs = conn.Execute(SQLstmt)
IF NOT RS.EOF THEN
%>

<table>
<FORM METHOD="post" ACTION="dataupdate.asp?Actionvar=update">
<INPUT TYPE="text" size="78" NAME="dataMessage"
VALUE="<%=rs("Message")%>">

<INPUT TYPE="hidden" NAME="flag" VALUE="2">
<INPUT TYPE="hidden" NAME="Recordid" VALUE="<%=rs("dataID")%>">
<INPUT TYPE="submit" VALUE="Update">
</form>
</table>

<%
rs.MoveNext
rs.Close
END IF
ELSEIF Request.Form("flag")="2" THEN
comnt = request.form("dataMessage")
kament = Replace(comnt, "'", "''")

SQLstmt = "UPDATE database SET "
SQLstmt = SQLstmt & "Message='" & kament & "' "
Aaron Bertrand [MVP]
Guest
 
Posts: n/a
#9: Jul 19 '05

re: help me with " sign in display of data in asp form


What he's suggesting is pretty simple. Change this:

<INPUT TYPE="text" size="78" NAME="dataMessage" VALUE="<%=rs("Message")%>">

To this:

<INPUT TYPE="text" size="78" NAME="dataMessage"
VALUE="<%=Server.HTMLEncode(rs("Message"))%>">

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


cooldv
Guest
 
Posts: n/a
#10: Jul 19 '05

re: help me with " sign in display of data in asp form


"Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message news:<#YdZxjl3DHA.484@TK2MSFTNGP10.phx.gbl>...[color=blue]
> What he's suggesting is pretty simple. Change this:
>
> <INPUT TYPE="text" size="78" NAME="dataMessage" VALUE="<%=rs("Message")%>">
>
> To this:
>
> <INPUT TYPE="text" size="78" NAME="dataMessage"
> VALUE="<%=Server.HTMLEncode(rs("Message"))%>">[/color]


Thank you, Bob Barrows for your solution and Aaron Bertrand for your clarification.

The above solution is working like a charm. Thanks again.
Closed Thread


Similar ASP / Active Server Pages bytes