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

2023-06-12 Thread e-letter
Yes, aware but one step at a time, slowly(!)

As a non-programmer, want to test ability to comprehend the concepts
first, before security implementations.

-- 
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 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



[PHP-DB] use php variable within postgresql query

2023-06-09 Thread e-letter
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