1

[EDIT]

I have a problem with connecting the postgresql database using php to the html page in such a way that the connection could send back and forth. I need to get specific values ​​from the database and display them in the form of a pie chart (preferably like with charts.js) I tried to do it on localhost in windows (necessary requirement). I run php and html on xampp, base supports pgadmin4. I changed ;extension=pdo_pgsql to extension=pdo_pgsql BUT now the error is this:

Warning: pg_query(): Query failed: ERROR: column "nazwa" relacji "tabelka1" does not exist LINE 1: INSERT INTO tabelka1(Nazwa, Opis, ID, Wartość) VALUES('fajna... ^ in C:\xampp\htdocs\DG\1\add.php on line 12 Error with query: ERROR: column "nazwa" relacji "tabelka1" does not exist LINE 1: INSERT INTO tabelka1(Nazwa, Opis, ID, Wartość) VALUES('fajna... ^

BUT WAIT! The column exists! https://i.stack.imgur.com/6hazn.jpg
I'm so confused right now... what am I supposed to do? Please be patient and try explain me step by step if anyone can...

<html>
<body>
    <?php
    $db = pg_connect('host=localhost port=5432 dbname=test1 user=postgres password=jajuszko123');

    $ID = pg_escape_string($_POST['ID']);
    $nazwa = pg_escape_string($_POST['nazwa']);
    $Opis = pg_escape_string($_POST['Opis']);
    $Wartość = pg_escape_string($_POST['Wartość']);

    $query = "INSERT INTO tabelka1(ID, Nazwa, Opis, Wartość) VALUES('" . $ID . "', '" . $nazwa . "', '" . $Opis . "', '" . $Wartość . "')";
    $result = pg_query($db,$query);
    if (!$result) {
        $errormessage = pg_last_error();
        echo "Error with query: " . $errormessage;
        exit();
    }
    printf ("These values were inserted into the database - %s %s %s", $ID, $nazwa, $Opis, $Wartość);
    pg_close();
    ?>
</body>
</html> 

I expect to get data values from my database and display it on html file.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • It says that `pg_connect` is not defined. You say you run xammp, so you have access to command line on the server. Go to the PHP installation directory, under bin and run `php -m`. It will list all the loaded modules. If PostgreSQL is not listed, your PHP installation does not have it. You would then need to load it, or rebuild your PHP with it (changing options in `./configure`, then `make`, and `make install`), or turn it on via php.ini file. – Nic3500 Jun 23 '19 at 04:11
  • Its not working (and btw i dont have command line access on windows - its not a server its just a pc) I reinstalled xammp and the only thing i found on php.ini was : "extension=pdo_psql" so i delete ";" befor it and restart apache server. it just changed a error like this: Warning: pg_query(): Query failed: ERROR: column "nazwa" relation "tabelka1" does not exist LINE 1: INSERT INTO tabelka1(Nazwa, Opis, ID, Wartość) VALUES('fajna... ^ in C:\xampp\htdocs\DG\1\add.php on line 12 Error with query: BŁĄD: kolumna "nazwa" relacji "tabelka1" nie istnieje LINE 1: INSERT INTO ... – Paweł Franek Jun 23 '19 at 11:45
  • So you got PostgreSQL to work, not it is a matter of fixing that query.Check your columns, you want to add something in column "nazwa" which does not exist in table "tabelka1" (what the error message says). – Nic3500 Jun 24 '19 at 01:33

0 Answers0