Hey. For some reason, JSON is not inserted into the database. Made CREATE TABLE searches(id serial PRIMARY KEY, data jsonb NOT NULL); , after which I created a connection and try to put the data into the table:

 if(isset($_POST['data']) && !empty($_POST['data'])) { $data = $_POST['data']; //DB $db = getdb(); $query = "INSERT INTO searches (data) VALUES ('$data') RETURNING id"; $result = pg_query($query) or die('Query failed: ' . pg_last_error()); pg_close($db); echo $result; } 

But an error occurs in the line for creating the $query variable:

Notice: Array to string conversion

How to fix?

    1 answer 1

     $data = json_encode($_POST['data']);