Re: Select Where using character varying ??

From: Mariusz Pękala <skoot(at)qi(dot)pl>
To: pgsql-php(at)postgresql(dot)org
Subject: Re: Select Where using character varying ??
Date: 2006-10-03 20:03:53
Message-ID: 20061003200353.GA8719@cthulhu.sdi.tpnet.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

> 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.

--
Ceterum censeo Internet Explorer esse delendam.

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Robert Treat 2006-10-04 00:48:08 Re: Select Where using character varying ??
Previous Message DCarrero 2006-10-03 12:57:19 Re: Select Where using character varying ??