Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id DA16A9FB1EE for ; Tue, 3 Oct 2006 05:34:13 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 08407-10 for ; Tue, 3 Oct 2006 08:34:03 +0000 (UTC) X-Greylist: delayed 00:28:28.465444 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 68BF39FB2A3 for ; Tue, 3 Oct 2006 05:34:02 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from tiggs.net (206-223-169-74.beanfield.net [206.223.169.74]) by svr4.postgresql.org (Postfix) with ESMTP id EC43A5AF027 for ; Tue, 3 Oct 2006 08:05:31 +0000 (GMT) Received: from localhost (206-223-169-82.beanfield.net [206.223.169.82]) by tiggs.net (Postfix) with ESMTP id 335D327EB4B; Tue, 3 Oct 2006 03:05:32 -0500 (CDT) Received: from tiggs.net ([206.223.169.74]) by localhost (mx1.hub.org [206.223.169.82]) (amavisd-new, port 10024) with ESMTP id 69316-10; Tue, 3 Oct 2006 08:05:31 +0000 (UTC) Received: from [10.0.1.201] (unknown [68.187.34.210]) by tiggs.net (Postfix) with ESMTP id 4B7C227EB4A; Tue, 3 Oct 2006 03:05:31 -0500 (CDT) Message-ID: <452219C8.4010200@tiggs.net> Date: Tue, 03 Oct 2006 03:05:28 -0500 From: Charley Tiggs User-Agent: Thunderbird 1.5.0.7 (Macintosh/20060909) MIME-Version: 1.0 To: ben wilko Cc: pgsql-php@postgresql.org Subject: Re: Select Where using character varying ?? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200610/2 X-Sequence-Number: 3602 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
"; /*exit;*/} > $Sem_No = pg_Result($Sem_No, 0); > > // Error Message > > *Warning*: pg_exec() [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