Re: [PHP-DB] use php variable within postgresql query

2023-06-12 Thread Karl DeSaulniers
Oh I see now I am late to the conversation. Slow email load. Carry on.

> On Jun 12, 2023, at 1:42 PM, Karl DeSaulniers  wrote:
> 
> Hi,
> I am assuming this is just a typo in your post and not your code, correct? 
> (see quoted text below)
> If not, then try the other bracket?
> 
> $query=$_GET['databasecolumn'];
> 
> 
>> On Jun 9, 2023, at 4:05 AM, e-letter  wrote:
>> 
>> $query=$_GET['databasecolumn'[;
> 

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] use php variable within postgresql query

2023-06-12 Thread Karl DeSaulniers
Hi,
I am assuming this is just a typo in your post and not your code, correct? (see 
quoted text below)
If not, then try the other bracket?

$query=$_GET['databasecolumn'];


> On Jun 9, 2023, at 4:05 AM, e-letter  wrote:
> 
> $query=$_GET['databasecolumn'[;



Re: [PHP-DB] use php variable within postgresql query

2023-06-12 Thread Michael Oki
Meanwhile, you should probably use prepared statements to avoid SQL
injection.

On Mon, 12 Jun 2023 at 16:03, e-letter  wrote:

> First, sorry for the mistake to type a sanitised version of code.
> Should have been:
> "$query=$_GET['databasecolumn'];"
>
> After some rtfm, confused as a non-computer-programmer why it is
> necessary to set the $_GET parameter.
>
> The overall simple scenario is to view a postgresql database in a
> series of html web pages of more details of data ("drill down"?).
>
> php code within html file 1:
> "
> $databasequery=pg_query($databaseconnection,'SELECT
> databasecolumn1,
> databasecolumn2 FROM databasetable');
> if (!$databasequery) {
> echo 'rubbish code';
> exit;
> }
> while
> ($databasequery1=pg_fetch_assoc($databasequery)) {
> echo '
>  href="localfile.php?databasecolumn1='.$databasequery1['databasecolumn1'].'">'.$databasequery1['databasecolumn1'].'';
> echo ' '
> .$databasequery1['databasecolumn2'].'';
> ';
> }
> "
>
> The first html file shows successfully the a list of hyperlinks from
> the database, for tuples in 'databasecolumn1'. The desired behaviour
> is that the second html file shows another database query result for
> each tuple in the first html file, i.e. more detail from the database
> for each tuple in 'databasecolumn1'.
>
>
> php code within html file 2:
> "
> $databasequery2=pg_query($databasequery1);
> $databasequery3=pg_query("SELECT * FROM databasetable WHERE
> databasecolumn1='{$databasequery2['databasecolumn']}'");
> echo $databasequery3
> "
>
> The html file 2 shows:
> "
> resource id#3
> "
>
> The expected result was to show all columns for the row constraint
> (...WHERE ...)
>
> It seems that the use of a php variable within a postgresql query is
> not understood. What relevant terminology to read next please?
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
*Thanks In Advance,*

*Michael OKI*

*CBSA*
*Technologist*
*+34663549276*
*"Impossible Is Nothing"*

*Scan and share QR codes on the mycodescanner
app*


BTA Certified Blockchain Solution Architect & IEEE member
https://michaeloki.blogspot.com


Re: [PHP-DB] use php variable within postgresql query

2023-06-12 Thread e-letter
First, sorry for the mistake to type a sanitised version of code.
Should have been:
"$query=$_GET['databasecolumn'];"

After some rtfm, confused as a non-computer-programmer why it is
necessary to set the $_GET parameter.

The overall simple scenario is to view a postgresql database in a
series of html web pages of more details of data ("drill down"?).

php code within html file 1:
"
$databasequery=pg_query($databaseconnection,'SELECT databasecolumn1,
databasecolumn2 FROM databasetable');
if (!$databasequery) {
echo 'rubbish code';
exit;
}
while ($databasequery1=pg_fetch_assoc($databasequery)) {
echo '
'.$databasequery1['databasecolumn1'].'';
echo ' ' 
.$databasequery1['databasecolumn2'].'';
';
}
"

The first html file shows successfully the a list of hyperlinks from
the database, for tuples in 'databasecolumn1'. The desired behaviour
is that the second html file shows another database query result for
each tuple in the first html file, i.e. more detail from the database
for each tuple in 'databasecolumn1'.


php code within html file 2:
"
$databasequery2=pg_query($databasequery1);
$databasequery3=pg_query("SELECT * FROM databasetable WHERE
databasecolumn1='{$databasequery2['databasecolumn']}'");
echo $databasequery3
"

The html file 2 shows:
"
resource id#3
"

The expected result was to show all columns for the row constraint
(...WHERE ...)

It seems that the use of a php variable within a postgresql query is
not understood. What relevant terminology to read next please?

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] use php variable within postgresql query

2023-06-09 Thread Aziz Saleh
That was a bad copy/paste on his part. Syntax errors will not allow PHP to
even run the code.

On Fri, Jun 9, 2023 at 11:14 AM G. Franklin  wrote:

> My friends,
>
> Would not the syntax of "$query=$_GET['databasecolumn'[;" be part of the
> issue?
>
> I believe the brackets should be closed like this, no?
> "$query=$_GET['databasecolumn'];"
>
> ~G.
>
>
>
> On Fri, 9 Jun 2023 at 10:53, Aziz Saleh  wrote:
>
> > Read and understand these, should help you:
> >
> > https://www.php.net/manual/en/language.types.array.php
> >
> > Basically its databasecolumnname get param is not defined (set) causing
> the
> > query to fail also.
> >
> > On Fri, Jun 9, 2023 at 5:06 AM e-letter  wrote:
> >
> > > Readers,
> > >
> > > Suppose:
> > >
> > > $query=$_GET['databasecolumn'[;
> > >
> > > $anotherquery=pg_query($databaseconnection, 'SELECT * FROM
> > > databasename WHERE databasecolumnname="'.$query.';"');
> > >
> > > Two errors are reported:
> > >
> > > PHP Notice:  Undefined index: databasecolumnname
> > >
> > > PHP Warning:  pg_query(): Query failed: ERROR:  column ";" does not
> exist
> > >
> > > Any advice please?
> > >
> > > --
> > > PHP Database Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
>


Re: [PHP-DB] use php variable within postgresql query

2023-06-09 Thread G. Franklin
My friends,

Would not the syntax of "$query=$_GET['databasecolumn'[;" be part of the
issue?

I believe the brackets should be closed like this, no?
"$query=$_GET['databasecolumn'];"

~G.



On Fri, 9 Jun 2023 at 10:53, Aziz Saleh  wrote:

> Read and understand these, should help you:
>
> https://www.php.net/manual/en/language.types.array.php
>
> Basically its databasecolumnname get param is not defined (set) causing the
> query to fail also.
>
> On Fri, Jun 9, 2023 at 5:06 AM e-letter  wrote:
>
> > Readers,
> >
> > Suppose:
> >
> > $query=$_GET['databasecolumn'[;
> >
> > $anotherquery=pg_query($databaseconnection, 'SELECT * FROM
> > databasename WHERE databasecolumnname="'.$query.';"');
> >
> > Two errors are reported:
> >
> > PHP Notice:  Undefined index: databasecolumnname
> >
> > PHP Warning:  pg_query(): Query failed: ERROR:  column ";" does not exist
> >
> > Any advice please?
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>


Re: [PHP-DB] use php variable within postgresql query

2023-06-09 Thread Aziz Saleh
Read and understand these, should help you:

https://www.php.net/manual/en/language.types.array.php

Basically its databasecolumnname get param is not defined (set) causing the
query to fail also.

On Fri, Jun 9, 2023 at 5:06 AM e-letter  wrote:

> Readers,
>
> Suppose:
>
> $query=$_GET['databasecolumn'[;
>
> $anotherquery=pg_query($databaseconnection, 'SELECT * FROM
> databasename WHERE databasecolumnname="'.$query.';"');
>
> Two errors are reported:
>
> PHP Notice:  Undefined index: databasecolumnname
>
> PHP Warning:  pg_query(): Query failed: ERROR:  column ";" does not exist
>
> Any advice please?
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>