473,748 Members | 2,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Apostrophe

I realize there are many ways to handle Apostrophes in sql statements. The
problem I'm having is comparing a string with an Apostrophe entered by the
operator against the field in the DB (ie Field: Customer Name against
entered name by operator which includes an apostrophe). The function I use
works well with the string (what it does is replaces the Apostrophe with two
Apostrophes thus allowing the sql statement to work). However, how can you
get a comparable function to handle the field in the Sql statement? I'm
using MySql.

Aug 15 '05 #1
1 3080
Joel (jo**@ecsnj.com ) wrote:
: I realize there are many ways to handle Apostrophes in sql statements. The
: problem I'm having is comparing a string with an Apostrophe entered by the
: operator against the field in the DB (ie Field: Customer Name against
: entered name by operator which includes an apostrophe). The function I use
: works well with the string (what it does is replaces the Apostrophe with two
: Apostrophes thus allowing the sql statement to work). However, how can you
: get a comparable function to handle the field in the Sql statement? I'm
: using MySql.
I'm a tiny bit confused, but perhaps the following will help.

In php I use "mysql_escape_s tring()" to create a value that can be used
directly in an sql statement.

$Qval = mysql_escape_st ring($val);

$sql = "SELECT * FROM TBL WHERE MY_COL = '$Qval';

I don't worry about quotes or anything else cause the escape function does
that.

In Perl using DBI you would use the
"$quoted_st ring = $dbh->quote($string) ;" utility method in the same way.

Other languages and interfaces often have similar functions.

If you're typing the queries by hand (so to speak) then try
google: "mysql escaping string values" to get a list of ways to escape
things in strings within mysql.
--

This space not for rent.
Aug 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10440
by: Meyer1228 | last post by:
You all helped me with function keys last week. Thanks so much; your advice was right on. My question now - does anyone have a function that I can use to test my sql statements for the apostrophe and quote and do a search/replace type thing. I'd like something to put in my basFunctions module instead of replacing every time I do a sql command in my program code. Thanks!
2
7982
by: Michael Sterling | last post by:
i'm using delphi 7 and have a query in which i'm trying to find names that have an apostrophe in them, i.e. "o'mally". my problem is that when i write my select statement i can't get the quotes right. i get all types of errors no matter what i try. i get "missing right quote", "invalid token" etc. i've tried using QuotedStr and nothing works. here is my current attempt in which i get an "invalid use of keyword. token: n'%'" sSQL :=...
2
1649
by: InvisibleMan | last post by:
Thank in advance for your help... I have the following javascript: document.write(' <a class="whitenav" href="javascript:window.external.AddFavorite ('http://www.mydomain.com','Welcome to MyDomain.com')">Bookmark Site</a> |'); where the problem arises with the apostrophe's in:
13
11439
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices Restaurant" etc. automatically and programmatically during data entry? This would eliminate my concatinated strings from producing errors when I base the string on a query. Think this is an example of the "Dreaded Apostrophe Bug." If I enter a...
1
5376
by: congngo | last post by:
Hi all Every time I export a table into an excel spreadsheet. It has a leading apostrophe on every cells. This drive me nut. I have to do a work around by export table into a txt file than import in excel to get rid of the apostrophe. It has been happen about two months now before it didn't do that. It is only happen when I have text data type in the table. If I change to number data type then the problem go away but most of my...
1
300
by: spacehopper_man | last post by:
hi - I am having "apostrophe in sql" problems ;) I am executing a stored procedure on SQL Server - and passing in a string parameter. the string has a single apostrophe in it. the call is failing with an "Incorrect syntax" message.
1
4023
by: Rose | last post by:
Hi all, I'm trying to create a clickable link, but the pesky apostrophe is preventing the link from getting displayed properly. I'm displaying the contents of a folder (with contains the apostrophe), with the filename as a clickable link. The files show up properly, but the link location cuts off at the apostrophe. Here's a code snippet (fi is an instance of FileInfo):
2
12332
by: Tom | last post by:
Hi, I have some kind of problems with an apostrophe character ('). I would like to select from DataTable DataRow containing value horses' (with an apostrophe on the end). But when I do it in an obvious way, like this: DataTable dt = new DataTable(); DataColumn id = new DataColumn("ID", Type.GetType("System.Int32"));
9
3596
by: Thomas 'PointedEars' Lahn | last post by:
Jukka K. Korpela wrote: IBTD. For example, in English it is customary (and AIUI expected) to use the character that ’ represents should be used to delimit a quotation within direct speech (which itself should be delimited by “ and ”. (I gathered that from reading several English books.) I think you would agree that it would make especially English text with quotations in direct speech (say, in a novel where one person tells another...
4
2274
by: Razzbar | last post by:
I'm working on a bookmarklet that grabs information from a page and submits it to a server. Yet another social bookmarking application. I'm having trouble with page titles that include an apostrophe. I'm using encodeURIComponent() around the page title, and again around the URL. Apparently the browser is inserting a backslash before any apostrophe. I can see that when I write the $_GET data to a file in PHP on the server. When the GET...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.