So I’m running Ubuntu 18.04 on a Virtual Machine and I’m trying to have two docker containers interact with one another. I have php:apache installed one container and postgresql on the other. I’ve created a table on postgresql, however, when I try to use a php script to pull or insert data into the table, I get an error. Can someone help me resolve this?
PHP Script below:
<?php
$db_host = "localhost";
$db_username = "postgres";
$db_password = "kha";
$db_name = "postgres";
$con = pg_connect($db_host,$db_username,$db_password,$db_name);
if ($con->connect_error) {
die("Database connection failed: " . $con->connect_error);
}
if(isset($_POST['submit'])) {
$id=$_POST['id'];
$password=$_POST['password'];
$query = "INSERT INTO test.table1 (id, password)
VALUES ('$id', '$password')";
if (!pg_query($con, $query)) {
die('An error occurred. Your review has not been submitted.');
} else {
echo "Thanks for your review.";
}
}
?>