Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id D873C9FB26B for ; Tue, 3 Oct 2006 09:57:28 -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 93960-01 for ; Tue, 3 Oct 2006 12:57:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.178]) by postgresql.org (Postfix) with ESMTP id A5A259FB261 for ; Tue, 3 Oct 2006 09:57:24 -0300 (ADT) Received: by py-out-1112.google.com with SMTP id d80so2961006pyd for ; Tue, 03 Oct 2006 05:57:22 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=tUvPnq9dgB/Xuzwl87QV5PYTqUcK+wdepsQAbiu9/e+bIo7qVTUvGiuITdmyHoHq3z6V8f7ubc1tnDjxFPMHl7u1GceuP1MWAis8z0n+QnJDGKXkQ5fuk1SbVkwDLVY3/4WM6o5HNyqhEa7Ebwwp9Gsm7Rt1jAqkhOH2I47s7Do= Received: by 10.35.93.15 with SMTP id v15mr15489220pyl; Tue, 03 Oct 2006 05:57:20 -0700 (PDT) Received: by 10.35.68.15 with HTTP; Tue, 3 Oct 2006 05:57:19 -0700 (PDT) Message-ID: <5887d1f40610030557q6e3d097dl6b72f47e2b289185@mail.gmail.com> Date: Tue, 3 Oct 2006 08:57:19 -0400 From: DCarrero To: "Charley Tiggs" Subject: Re: Select Where using character varying ?? Cc: "ben wilko" , pgsql-php@postgresql.org In-Reply-To: <452219C8.4010200@tiggs.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <452219C8.4010200@tiggs.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.199 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE, SPF_PASS X-Spam-Level: X-Archive-Number: 200610/3 X-Sequence-Number: 3603 2006/10/3, Charley Tiggs : > 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); > > 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 > > ]: 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