Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

double quotes and number symbol are stripped out when submitting text data into SQL DB

Posted on 2004-08-03
21
Medium Priority
?
303 Views
Last Modified: 2013-12-24
I have a form with a text box.  When the user submits the form and reviews the submitted text in a browser the double quotes and # symbol that was submitted in the form is stripped out.  When the data is inserted into an SQL db table these symbols are removed as well.

Right now my code is:

<cfset form.attr=REREPLACENOCASE(form.attr,"[^(a-z|0-9|,|'|:|.|?|!|$|%|*|+|=|;|\-|\"")]"," ","ALL") > 

but I can't get the double quotes and number symbol to be excepted.
0
Comment
Question by:CTerreri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
21 Comments
 
LVL 5

Expert Comment

by:Seth_Bienek
ID: 11706358
Hello,

You can add the pound sign (#) and double-quotes (") to your regex easily by referencing their ascii codes (43 and 34, respectively):

<cfset form.attr=REREPLACENOCASE(form.attr,"[^(a-z|0-9|,|'|:|.|?|!|$|%|*|+|=|;|\-|\|#chr(43)#|#chr(34)#"")]"," ","ALL") >

Regards,

Seth
0
 

Author Comment

by:CTerreri
ID: 11707102
I can't get the pound sign to appear.  Is there something missing from the code?
0
 
LVL 5

Expert Comment

by:Seth_Bienek
ID: 11707357
Yes, a comma between #chr(34)# and "".

My bad. :)

Seth
0
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 

Author Comment

by:CTerreri
ID: 11707968
I'm still not getting this to work.  chr(34) is the ascii code for quotes and this is working.  If I change the code to:

<cfset form.attr=REREPLACENOCASE(form.attr,"[^(a-z|0-9|,|'|:|.|?|!|$|%|*|+|=|;|\-|\|#chr(43)#|#chr(34)#,"")]"," ","ALL") >

there is no change....The pound sign still does not appear.

Hmmmmm.....
0
 
LVL 5

Expert Comment

by:Seth_Bienek
ID: 11708090
Oddly enough, this works:

<cfset attr = rereplacenocase("This is some special text, with quotes: "", and hash marks: ##.", "[^(a-z|0-9|,|'|:|.|?|!|$|%|*|+|=|;|\-|\|##|#chr(34)#,"")]"," ","ALL") >

The difference is escaping the pound signs instead of using the ASCII code.  Weird.

Seth
0
 

Author Comment

by:CTerreri
ID: 11708407
When I view the output through the browser the pound symbol and double quotes appear as I would like.  However, when I review the data after inserting into the SQL db the text gets truncated right before the double quote symbol.  I think this has something to do with using the pound symbols in the REREPLACENOCASE function.

Is there a way to work around this?
0
 
LVL 5

Expert Comment

by:Seth_Bienek
ID: 11708646

Are you using <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.attr#"> in your query?

If not, try that. :)

Seth
0
 

Author Comment

by:CTerreri
ID: 11709739
I'm not using CFQUERY here. I'm passing hidden form variables from one form to another.  I do perform an INSERT within a CFQUERY on the last page using  the form variables.

I'm not sure what to do here.
0
 
LVL 5

Expert Comment

by:Seth_Bienek
ID: 11709779
Is the text correctly formatted right before it goes into the database?

Do a <cfdump><cfabort> directly above your <cfquery> tag..

Seth
0
 

Author Comment

by:CTerreri
ID: 11709917
the text is truncated right before the double quotes just as it appears in the db after the INSERT.
0
 

Author Comment

by:CTerreri
ID: 11710263
The text is being truncated when it gets passed to the next page and this is how I'm passing it:  

 <INPUT TYPE="hidden" NAME="ATTR"  SIZE=15   VALUE="#form.ATTR#">
0
 
LVL 5

Expert Comment

by:Seth_Bienek
ID: 11710320
Kill the "size" parameter in the input tag.

Not sure if this is the problem, but since you're specifying the value, you don't neet to validate the length.

Dose that fix it?

Seth
0
 

Author Comment

by:CTerreri
ID: 11710440
No it doesn't help.  I'm playing with the INPUT TAG to see if there's something else going on here.
0
 

Author Comment

by:CTerreri
ID: 11717584
I'm increasing the points to 500. To other experts,  do you have any input on this?
0
 
LVL 8

Expert Comment

by:MartinCMS
ID: 11726236
What is the format of your field in SQL?  Make sure it is nVarchar or Text, otherwise, you will have problem with double quotes and pound key.
0
 

Author Comment

by:CTerreri
ID: 11757612
I changed the field type from varchar to nvarchar and I still have the same problem: the text is being truncated  right before the double quote symbol.  I can verify that this occurs when it gets passed to the next page as a form variable.
0
 
LVL 5

Expert Comment

by:Seth_Bienek
ID: 11758973
Is the text truncated the very first time the form is submitted, or does it happen sometime between that first form post and the time it goes into the database?  Try using a <cfdump..> on every page in the process to find out at what point the text is being truncated.

Regards,

Seth
0
 
LVL 1

Accepted Solution

by:
cdman2k3 earned 2000 total points
ID: 11782398
I'm looking at that INPUT tag which this.....
     VALUE="#form.ATTR#"

If the form field has double quotes then the value of the input tag will be truncated. You might want to try this instead...

<INPUT TYPE="hidden" NAME="ATTR"  VALUE="#HTMLEditFormat(form.ATTR)#">

The generated HTML source will show   &quot;   where the form variable had a double quote but will be received by the next page as a double quote.

Try the following test files... open formtest.cfm in browser, and see the html generated by formtest2.cfm each time you click submit, and you'll notice that the form.attr survives, even when re-posted (from formtest2.cfm back to itself)

Example - formtest.cfm
<html><body>
<form action="formtest2.cfm" method="post">
<input type="hidden" name="attr" value="x&quot;x">
<input type="submit">
</form>
</body></html>

Example - formtest2.cfm
<html><body>
<cfoutput>form.attr == |#form.attr#|</cfoutput>
<form action="formtest2.cfm" method="post">
<cfoutput><input type="hidden" name="attr" value="#HTMLEditFormat(form.attr)#"></cfoutput>
<input type="submit">
</form>
</body></html>

By the way if you're performing queries to insert user edited data into a database be very careful of single quotes, otherwise if a user types something like   "don't need this"   you get ColdFusion errors... e.g. #PreserveSingleQuotes(form.attr)# inside the <cfquery> --- dead handy and something I invariably forget....
0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

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 …
What You Need to Know when Searching for a Webhost Provider
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

610 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