Solved

Single Quote Troubles

Posted on 2000-04-17
3
164 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
nginx with multiple websites --need help with phpmyadmin please 5 54
JKS to store upstart data 2 84
CFFILE upload help 98 138
.htacess file 301 redirects that are strange 4 46
This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

912 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

20 Experts available now in Live!

Get 1:1 Help Now