Solved

Single Quote Troubles

Posted on 2000-04-17
3
163 Views
Last Modified: 2013-12-24
I create a values list for use in a cfquery insert query.  The trouble is if there is a single quote in the data, the whole thing goes kerplunk!  Heres an example.

<cfset fullname="David Perry">
<cfset comments="I'll be back">

<cfset q="'">
<cfset values=q & fullname & q & "," & q & comments & q>

<cfquery name="test" datasource="test">
     INSERT INTO Table1(Name,Comments)
     VALUES(#preservesinglequotes(values)#)
</cfquery>

Any help would be greatly appreciated.

:) dapperry
0
Comment
Question by:dapperry
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
Unifex earned 100 total points
ID: 2725204
If you double up on the single quotes in the comments string it works fine.  Use this line instead:

<cfset values=q & fullname & q & "," & q & replace(comments,"'","''") & q>

The debugging info will include the doubled up single quote but the table will record the entry as a single quote.

Au.
0
 
LVL 2

Expert Comment

by:Unifex
ID: 2725208
Hmm...  That looks bad on my screen.  While cutting and pasting will work what that replace statement says is:

replace(comments,[dq][sq][dq],[dq][sq][sq][dq])

....where [dq] is double quote (") and [sq] is single quote(').

Au.
0
 
LVL 3

Author Comment

by:dapperry
ID: 2726874
Thanks that worked great.  It is kinda of pain though to have to use the replace.  Oh well...

:) dapperry
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now