473,699 Members | 2,877 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 3075
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
10435
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
7981
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
1648
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
11425
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
5373
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
4022
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
12326
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
3594
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
2272
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
8704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8940
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7781
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
6546
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
5879
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
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
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
2362
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.