[svlug] PHP database code not...

Jesse Monroy jesse650 at gmail.com
Wed Nov 12 23:24:01 PST 2014


check pg_query for error return

FWIW: http://php.net/manual/en/function.var-dump.php

Jesse

Sent from my Samsung Tab2
On Nov 12, 2014 11:04 PM, "Michael Robinson" <plug_1 at robinson-west.com>
wrote:

> On Wed, 2014-11-12 at 21:59 -0700, Jesse Monroy wrote:
> > SEE BELOW
> >
> > On 11/12/14, Michael Robinson <plug_1 at robinson-west.com> wrote:
> > > working as expected.
> > >
> > > postgres=# select * from computers where computer_name='open';
> > >  computer_name | computer_id
> > > ---------------+-------------
> > >  open          |         112
> > > (1 row)
> > >
> > > postgres=# select * from computers;
> > >  computer_name | computer_id
> > > ---------------+-------------
> > >  cheetah       |         100
> > >  eagle64       |         101
> > >  heron         |         102
> > >  heron64       |         103
> > >  penguin       |         104
> > >  tuna          |         105
> > >  ultravision   |         106
> > >  luke          |         107
> > >  barbara       |         108
> > >  wii           |         109
> > >  silene        |         110
> > >  swan          |         111
> > >  open          |         112
> > >
> > > The database is postgresql-9.3.
> > > So the psql command output on the database host is above and the
> > > following PHP code doesn't produce similar results:
> > >
> > > ...
> > > foreach ( $_POST['computers'] as $setcomp )
> > > {
> > >           chop ($setcomp);
> > >
> > >           $query =  "SELECT * FROM computers WHERE computer_name ";
> > >
> > WHERE computer_name (?)
> >
> > Jesse
> The next line is missing, it extends the query string.
>
> $query .= "= '$setcomp';";
>
> The echo "$query"; line is there for debugging purposes.
>
> Finally, there is an internal foreach loop that outputs the values
> retrieved by the queries where the numbers come back wrong.
>
> Below is output from a run of this PHP script.
> ------------------------------------------------------
> Cleared old user to computer associations for michael.
> SELECT * FROM computers WHERE computer_name = 'open';
>
> open
>
> 106
> SELECT * FROM computers WHERE computer_name = 'eagle64';
>
> eagle64
>
> 106
> SELECT * FROM computers WHERE computer_name = 'wii';
>
> wii
>
> 106
> SELECT * FROM computers WHERE computer_name = 'silene';
>
> silene
>
> 106
> SELECT * FROM computers WHERE computer_name = 'heron';
>
> heron
>
> 100
> SELECT * FROM computers WHERE computer_name = 'heron64';
>
> heron64
>
> 109
> SELECT * FROM computers WHERE computer_name = 'ultravision';
>
> ultravision
>
> 110
>
> Exit
>
>
> _______________________________________________
> svlug mailing list
> svlug at lists.svlug.org
> http://lists.svlug.org/lists/listinfo/svlug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.svlug.org/archives/svlug/attachments/20141113/26d0e374/attachment.htm


More information about the svlug mailing list