[svlug] PHP database code not...

Michael Robinson plug_1 at robinson-west.com
Wed Nov 12 22:04:28 PST 2014


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





More information about the svlug mailing list