In this example we use 3 file for Delete record or Data using PostgreSQL and PHP.
<?php
include_once 'database.php';
$result = pg_query($db,"SELECT * FROM employee");
?>
<!DOCTYPE html>
<html>
<head>
<title>Delete employee data</title>
</head>
<body>
<table>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>City</td>
<td>Email id</td>
<td>Action</td>
</tr>
<?php
$i=0;
while($row=pg_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $row["first_name"]; ?></td>
<td><?php echo $row["last_name"]; ?></td>
<td><?php echo $row["city_name"]; ?></td>
<td><?php echo $row["email"]; ?></td>
<td><a href="delete_process.php?userid=<?php echo $row["userid"]; ?>">Delete</a></td>
</tr>
<?php
$i++;
}
?>
</table>
</body>
</html>
<?php
$host = "host = 127.0.0.1";
$port = "port = 5432";
$dbname = "dbname = testdb";
$credentials = "user = postgres password=pass123";
$db = pg_connect( "$host $port $dbname $credentials" );
?>
<?php
include_once 'database.php';
$query = "DELETE FROM employee WHERE userid='" . $_GET["userid"] . "'";
if($result = pg_query($query)){
echo "Data Deleted Successfully.";
}
else{
echo "Error.";
}
?>