Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 8A0A864FC85 for ; Fri, 2 Jan 2009 16:14:28 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 09876-10 for ; Fri, 2 Jan 2009 16:14:22 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.180]) by mail.postgresql.org (Postfix) with ESMTP id 16D1B64FC83 for ; Fri, 2 Jan 2009 16:14:21 -0400 (AST) Received: by wa-out-1112.google.com with SMTP id j4so3587682wah.19 for ; Fri, 02 Jan 2009 12:14:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=M9RgnIY7HYIyFDhjc6dYilqg64yx9rzNJPjxc53DDp8=; b=x05lsAlJVHXKVo4Ux4uhfhAREu1mzRzSpB2VPxV/2RUh3yR7TMGeA195TOmYT5hOsc h+mLbjulMIz/JoKUIUMmcuyhlu/yIZIe6N+Wpr1vp9jazor2R1f/SxASRbzqq7QTTrSk GIZwDeenFcNQI3dg9Rd3dfo+eum4UleYLzN7s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=Eh3oYOpg/9aN1HtuULfHAAL8hOPCQsD1YQ2wdlQL4Y7Vq8jktjGwXoc47zCqXqbiDS QOp5LHwNwoQuqNWM3gt2O3v+OTbEN01igTaGtm+blE+bHu2LbokFciTv6Bwee6gsC9QW IxOHpgVO/oygOsoNRBwBWTkNx4L5y6cBtJ2ns= Received: by 10.114.145.1 with SMTP id s1mr11988032wad.118.1230927260909; Fri, 02 Jan 2009 12:14:20 -0800 (PST) Received: by 10.114.135.4 with HTTP; Fri, 2 Jan 2009 12:14:20 -0800 (PST) Message-ID: Date: Fri, 2 Jan 2009 13:14:20 -0700 From: "Scott Marlowe" To: "Marc Fromm" Subject: Re: access data in php Cc: "pgsql-admin@postgresql.org" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200901/8 X-Sequence-Number: 31055 On Fri, Jan 2, 2009 at 12:40 PM, Marc Fromm wrote: > This is my code: > $dbconn = pg_connect("host=localhost port=5432 user=postgres dbname=studentalerts"); > > if(isset($_GET["value"])){ > $w_number=$_GET["value"]; > } You need to scrub user input. use pg_escape_string($_GET['value']) > //echo $w_number; > > $query = "select first_name, last_name, alert from alert_list where w_number='$w_number'"; > $result = pg_query($dbconn,$query); > if (!$result) { > echo "Problem with query " . $query . "
"; > echo pg_last_error(); > exit(); > } > > $rows = pg_fetch_assoc($result); Change this to $rows = pg_num_rows($result); > if ($rows==0){ > echo "There are no alerts for $w_number!\n\n"; > }else{ > $result = pg_query($dbconn,$query); > $count=1; > while ($row = pg_fetch_array($result)){ > echo "Alert $count: "; > echo htmlspecialchars($row['first_name']) . " "; > echo htmlspecialchars($row['last_name']); > echo "\n"; > echo htmlspecialchars($row['alert']); > echo "\n\n"; > $count++; > } > } > if ($w_number==""){echo "Enter a W number!\n\n";} > echo "End of line"; > > pg_free_result($result); > pg_close($dbconn); > ?> > > -----Original Message----- > From: Scott Marlowe [mailto:scott.marlowe@gmail.com] > Sent: Friday, January 02, 2009 10:28 AM > To: ioguix@free.fr > Cc: Marc Fromm; pgsql-admin@postgresql.org > Subject: Re: [ADMIN] access data in php > > On Fri, Jan 2, 2009 at 11:09 AM, wrote: >> pg_fetch_assoc behave like pg_fetch_array: it increments the internal >> pointer to the current result. >> So if you call it once, then pg_fetch_array will return the 2nd result >> in the result set. > > Wow, I'm so used to seeing > > $rows = pg_num_rows() that that's what I saw up there. > -- When fascism comes to America, it will be draped in a flag and carrying a cross - Sinclair Lewis