To create a question for a given user in PostgreSQL using PHP

I have a list of urls on my homepage that looks like SO in the following form

<a href="?questions&questions=777">link1</a>
<a href="?questions&questions=666">link2</a>

The following PHP script has a problem in the parameter $_GET.

 $dbconn = pg_connect("host=localhost port=5432 dbname=masi user=masi password=123");
 // A QUESTION SELECTED BY USER 
 // to generate the answers for the given question 
     $result = pg_prepare($dbconn, "query9", "SELECT title, answer
         FROM answers 
         WHERE questions_question_id = $1;");            // WARNINGS refer HERE
     // TODO I am not sure if the syntax is correct for parametr inside $_GET                             
     $result = pg_execute($dbconn, "query9", array($_GET["'question_id' = $questions_question_id"]));
           // Problem HERE inside the $_GET

Thanks to Nose and Cihan for solving the problem with $ dbconn and for Simon to solve the main problem of this topic!

How can you only get question_id from the url so that Postgres understands the request?

0
source share
2 answers

It seems that the problem is not in the request, but in the connection to the database (dbconn)

+5
source

$_GET . , "" , , :

<a href="?questions=777">link1</a>

ID 777 :

$question_id = $_GET['questions'];

, pg_execute() , . $questions_question_id - .

, , (.. ).

$question_id = filter_input(INPUT_GET, 'questions', FILTER_SANITIZE_NUMBER_INT);

PHP 5.2 . . http://php.net/manual/en/function.filter-input.php

filter_input() null, GET .

+1
source

Source: https://habr.com/ru/post/1714690/


All Articles