Table creation:

CREATE TABLE “test”
(
CountryID varchar(255) NOT NULL,
CountryName varchar(255) NOT NULL,
PRIMARY KEY  (CountryID)
)

code:

<?php

ini_set(“display_errors”,”Off”);
if ($_POST[‘submit’]) {
// attempt a connection
$dbh = pg_connect(‘host=localhost dbname=postgres user=postgres password=admin port=5432’);
if (!$dbh) {
die(“Error in connection: ” . pg_last_error());
}

// escape strings in input data
$code = $_POST[‘ccode’];
$name = $_POST[‘cname’];

// execute query
$sql = “INSERT INTO test (countryid, countryname) VALUES (‘$code’, ‘$name’)”;
$result = pg_query($dbh, $sql);
if (!$result) {
die(“Error in SQL query: ” . pg_last_error());
}

echo “Data successfully inserted!”;

// free memory
pg_free_result($result);

// close connection
pg_close($dbh);
}
?>

<form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” method=”post”>
Country code: <br>
<input type=”text” name=”ccode” >
<p> Country name: <br>
<input type=”text” name=”cname”>
<p>
<input type=”submit” name=”submit”>
</p>
</form>