From: Robert Treat <xzilla@users.sourceforge.net>
To: pgsql-php@postgresql.org
Cc: Mariusz Pękala <skoot@qi.pl>
Subject: Re: Select Where using character varying ??
Date: Tue, 3 Oct 2006 20:48:08 -0400
Message-ID: <200610032048.09195.xzilla@users.sourceforge.net> (raw)
In-Reply-To: <20061003200353.GA8719@cthulhu.sdi.tpnet.pl>
References: <BAY116-F1074C7ACE9E04AA4A018B88F1C0@phx.gbl>
<5887d1f40610030557q6e3d097dl6b72f47e2b289185@mail.gmail.com>
<20061003200353.GA8719@cthulhu.sdi.tpnet.pl>
On Tuesday 03 October 2006 16:03, Mariusz Pękala wrote:
> > I think you should try:
> > $Sem_No = pg_Exec($conn,"SELECT seminar_id FROM seminar WHERE name
> > =\"$Sem\"");
>
> Double quotes are for quoting column names, not string constants.
>
> > $Sem_No = pg_Exec($conn,"SELECT seminar_id FROM seminar WHERE name
> > ='$Sem'");
>
> Better, but all strings, especially provided by some user, should be
> treated by the function pg_escape_string.
>
> Consider that some user types in a form field a text like this:
>
> '; delete from seminar where ''='
>
> When you add single quotes you get two valid queries. One of them is
> what you would never want to be executed ;-)
>
> And, by the way - pg_exec is a deprecated name AFAIK. The new one is
> pg_query.
probably even better would be to use pg_prepare and pg_execute.
--
Robert Treat
Build A Brighter LAMP :: Linux Apache {middleware} PostgreSQL
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-php@postgresql.org
Cc: xzilla@users.sourceforge.net, skoot@qi.pl
Subject: Re: Select Where using character varying ??
In-Reply-To: <200610032048.09195.xzilla@users.sourceforge.net>
References: <BAY116-F1074C7ACE9E04AA4A018B88F1C0@phx.gbl> <5887d1f40610030557q6e3d097dl6b72f47e2b289185@mail.gmail.com> <20061003200353.GA8719@cthulhu.sdi.tpnet.pl> <200610032048.09195.xzilla@users.sourceforge.net>
* 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