pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: DCarrero <dcarreroc@gmail.com>
To: Charley Tiggs <lists@tiggs.net>
Cc: ben wilko <wilko_ben@hotmail.com>
Cc: pgsql-php@postgresql.org
Subject: Re: Select Where using character varying ??
Date: Tue, 3 Oct 2006 08:57:19 -0400
Message-ID: <5887d1f40610030557q6e3d097dl6b72f47e2b289185@mail.gmail.com> (raw)
In-Reply-To: <452219C8.4010200@tiggs.net>
References: <BAY116-F1074C7ACE9E04AA4A018B88F1C0@phx.gbl>
	<452219C8.4010200@tiggs.net>

2006/10/3, Charley Tiggs <lists@tiggs.net>:
> ben wilko wrote:
> > Hi Guys
> >
> > I am printing names into a combo box and posting the variable. I try and use the
> > name ($Sem) in an SQL statement; WHERE name = $Sem; but I get an error which is
> > displayed near the end of this message. Are we able compare php string to
> > postgresql character varying??  not sure how else to do the selection
> >
> >
> > $conn = pg_Connect("host=localhost dbname=#### user=#### password=####");
> >    if (!$conn) {echo "An database connection error occurred.\n"; exit;}
> >
> >
> > // e.g. $Sem = "seminar one";
> >
> > $Sem = $_POST['Seminars'];
> >
> >
> > $Sem_No = pg_Exec($conn,"SELECT seminar_id FROM seminar WHERE name = $Sem");
> >  if (!$SemNo) {echo "A query error occurred in retreiving the selected seminar's
> > ID <br>"; /*exit;*/}
> > $Sem_No = pg_Result($Sem_No, 0);
> >
I think you should try:
$Sem_No = pg_Exec($conn,"SELECT seminar_id FROM seminar WHERE name =\"$Sem\"");
OR
$Sem_No = pg_Exec($conn,"SELECT seminar_id FROM seminar WHERE name ='$Sem'");
OR
$Sem_No = pg_Exec($conn,"SELECT seminar_id FROM seminar WHERE name
='".$Sem."';";);
or something like this for escape "seminar one" with " " inside the sql query

But i look the table description you still compare a integer row with
a string row
try maki the query like this:
$Sem_No = pg_Exec($conn,"SELECT name FROM seminar WHERE name =
 '$Sem'");
> > // Error Message
> >
> > *Warning*: pg_exec() [function.pg-exec
> > <http://www.citanalyst.com/jet/form/function.pg-exec;]: Query failed: ERROR:
> > syntax error at or near "one" at character 54 in
> > */home/bdwilko/public_html/jet/form/insertP.php* on line *56*
> > A query error occurred in retreiving the selected seminar's ID
> >
>
> Make sure that you're quoting the value you want to compare.  At a quick
> glance, this where the error is:
>
> $Sem_No = pg_Exec($conn,"SELECT seminar_id FROM seminar WHERE name = $Sem");
>
> should be:
>
> $Sem_No = pg_Exec($conn,"SELECT seminar_id FROM seminar WHERE name =
> '$Sem'");
>
> To be more accurate, you should probabley do:
>
> $Sem = pg_escape ( $Sem );
> $Sem_No = pg_Exec($conn,"SELECT seminar_id FROM seminar WHERE name =
> '$Sem'");
>
> Charley
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>        choose an index scan if your joining column's datatypes do not
>        match
>
Daniel Carrero Canales



view thread (5+ messages)  latest in thread

Message-ID: <5887d1f40610030557q6e3d097dl6b72f47e2b289185@mail.gmail.com>
Permalink:  ../5887d1f40610030557q6e3d097dl6b72f47e2b289185@mail.gmail.com/
Also on:    postgresql.org/message-id/5887d1f40610030557q6e3d097dl6b72f47e2b289185@mail.gmail.com

 · 

reply

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: dcarreroc@gmail.com, lists@tiggs.net, wilko_ben@hotmail.com
  Subject: Re: Select Where using character varying ??
  In-Reply-To: <5887d1f40610030557q6e3d097dl6b72f47e2b289185@mail.gmail.com>
  References: <BAY116-F1074C7ACE9E04AA4A018B88F1C0@phx.gbl> <452219C8.4010200@tiggs.net> <5887d1f40610030557q6e3d097dl6b72f47e2b289185@mail.gmail.com>

* 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