pg_connect() is showing the error in table format.Instead of showing error message as table format need a error message alert.
Error Message
To hide the error text generated by PHP, add @ in front of the function call, e.g.:
$conn = @pg_connect("host=$HOST dbname=$DBNAME user=$USER ". "password=$PASSWORD sslmode=disable");
More details here