From: Bruce Momjian <maillist@candle.pha.pa.us>
To: dionysos@dionysia.org
Cc: daniele@orlandi.com
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] What do I need to escape in an Insert ?
Date: Fri, 31 Jul 1998 01:01:05 -0400 (EDT)
Message-ID: <199807310501.BAA11175@candle.pha.pa.us> (raw)
In-Reply-To: <Pine.BSF.3.96.980730212535.2790A-100000@dionysia.org>
> On Fri, 31 Jul 1998, Daniele Orlandi wrote:
> > Suppose I'm going to insert the content of a <TEXTAREA> in a
> > table. Obviously, there will be characters that could potentially
> > confuse the SQL statement. What (and how) do I need to escape the
> > data to make it acceptable for an Insert ? I currently use the
> > PHP's addlashed function, is it enought ?
>
> I'm not sure if PHP's addslashes command will take care of single
> quotes, I haven't tried it yet. I believe the proper escape for a
> single quote in SQL is to put another single quote in front of it.
> So if a person's last name is "O'Brien" it would be inserted as:
>
> INSERT INTO personel (fname,lname) VALUES ('Michael','O''Brien');
>
> So what I do is a Regular Expression Replace in PHP, like this:
>
> $lname = ereg_replace("'", "''", $lname);
But this does not handle backslashes in the string. I think the PHP
function does both.
--
Bruce Momjian | 830 Blythe Avenue
maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026
+ If your life is a hard drive, | (610) 353-9879(w)
+ Christ can be your backup. | (610) 853-3000(h)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: maillist@candle.pha.pa.us, dionysos@dionysia.org, daniele@orlandi.com
Subject: Re: [SQL] What do I need to escape in an Insert ?
In-Reply-To: <199807310501.BAA11175@candle.pha.pa.us>
References: <Pine.BSF.3.96.980730212535.2790A-100000@dionysia.org> <199807310501.BAA11175@candle.pha.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox