Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: single quote dilemma


Message #1 by "dick r." <dickonthego@h...> on Tue, 27 Feb 2001 13:29:15 +0000
I'm caught in a vicious circle, need help!



I tried using a variable selTitle to avoid the problem of single quotes

(apostrophe) in  a string but it doesn't help. Using POST or GET show the

same problem. 



If I delete the single quote after VALUE, selTitle doesn't pass on multiple

words in a title in the Form request object. If I include it then I get an

error for titles that have an apostrophe (e.g. Carlito's Way)



 selTitle = rsSel("Title")

       Response.Write "<TR><TD><INPUT TYPE=Checkbox NAME=title VALUE='" &

selTitle &  "'> " & selTitle & "</TD>" 



Same problem occurs in a SQL statement.

Please advise complete solution not just a code equivalent for single or

double quotes.



Many Thanks,



Dick





Message #2 by "Ken Schaefer" <ken@a...> on Wed, 28 Feb 2001 10:16:34 +1100
There is *no* problem having a single quote in a string:



strVar = "Carlito's Way"



The only problem you will have is using the variable in an SQL string, since

SQL uses ' as delimiters.

The solution is to escape the single quote by doubling all single quotes

using the Replace() function before you put the variable into your SQL

string:



strVar = Replace(strVar, "'", "''")



Cheers

Ken



----- Original Message -----

From: "dick r." <dickonthego@h...>

To: "ASP Web HowTo" <asp_web_howto@p...>

Sent: Wednesday, February 28, 2001 12:29 AM

Subject: [asp_web_howto] single quote dilemma





> I'm caught in a vicious circle, need help!

>

> I tried using a variable selTitle to avoid the problem of single quotes

> (apostrophe) in  a string but it doesn't help. Using POST or GET show the

> same problem.

>

> If I delete the single quote after VALUE, selTitle doesn't pass on

multiple

> words in a title in the Form request object. If I include it then I get an

> error for titles that have an apostrophe (e.g. Carlito's Way)

>

>  selTitle = rsSel("Title")

>        Response.Write "<TR><TD><INPUT TYPE=Checkbox NAME=title VALUE='" &

> selTitle &  "'> " & selTitle & "</TD>"

>

> Same problem occurs in a SQL statement.

> Please advise complete solution not just a code equivalent for single or

> double quotes.

>

> Many Thanks,

>

> Dick

>





Message #3 by "Wally Burfine" <oopconsultant@h...> on Tue, 27 Feb 2001 23:43:22 -0000
Try this:



selTitle = "Carlito's Way"

selTitle = Replace(selTitle,"'","''")

Response.Write "<TR><TD><INPUT TYPE=Checkbox NAME=title VALUE='" &

selTitle &  "'> " & selTitle & "</TD>"



Regards,

Wally



>From: "dick r." <dickonthego@h...>

>Reply-To: "ASP Web HowTo" <asp_web_howto@p...>

>To: "ASP Web HowTo" <asp_web_howto@p...>

>Subject: [asp_web_howto] single quote dilemma

>Date: Tue, 27 Feb 2001 13:29:15 +0000

>

>I'm caught in a vicious circle, need help!

>

>I tried using a variable selTitle to avoid the problem of single quotes

>(apostrophe) in  a string but it doesn't help. Using POST or GET show the

>same problem.

>

>If I delete the single quote after VALUE, selTitle doesn't pass on multiple

>words in a title in the Form request object. If I include it then I get an

>error for titles that have an apostrophe (e.g. Carlito's Way)

>

>  selTitle = rsSel("Title")

>        Response.Write "<TR><TD><INPUT TYPE=Checkbox NAME=title VALUE='" &

>selTitle &  "'> " & selTitle & "</TD>"

>

>Same problem occurs in a SQL statement.

>Please advise complete solution not just a code equivalent for single or

>double quotes.

>

>Many Thanks,

>

>Dick



Message #4 by "dick roemer" <dickonthego@h...> on Wed, 28 Feb 2001 02:18:37
> Try this:

> 

> selTitle = "Carlito's Way"

> selTitle = Replace(selTitle,"'","''")

> Response.Write "<TR><TD><INPUT TYPE=Checkbox NAME=title VALUE='" &

> selTitle &  "'> " & selTitle & "</TD>"

> 



Problems still not solved but appreciate yr helpful solution. The title is 

extracted from a database and could be anything.



I tried this:

selTitle = rsSel("Title")

 selTitle = Replace(selTitle,"'","''")



    Response.Write "<TR><TD><INPUT TYPE=Checkbox NAME=title VALUE='" & 

selTitle & "'> " & selTitle & "</TD>" 



My form shows the titles with a double apostrophe like this Carlito''s 

Way - not good and the link to thenext page doesn't show a title.



On the linking page where I have an SQL statement yr suggestion worked 

much better, I didn't get an error but the title was truncated at the 

apostrophe.



 



Message #5 by "Wally Burfine" <oopconsultant@h...> on Wed, 28 Feb 2001 14:07:27 -0000
Actually, I think the correct way would be:



selTitle = "Carlito's Way"

Response.Write "<TR><TD><INPUT TYPE=Checkbox NAME=title VALUE='" &

Replace(selTitle,"'","''") &  "'> " & selTitle & "</TD>"



What is probably happening here is that the display contains 2 single quotes 

while the value only contains one. View the source and check that out.

What the HTML would look like is:



<TR><TD><INPUT TYPE=Checkbox NAME=title

VALUE='Carlito''s Way'>Carlito's Way</TD>







Regards,

Wally


  Return to Index