База данных, которую я использую - postgres. Соединение с базой данных находится в config.php, и оно работает, потому что я использовал его для заполнения таблицы. Тем не менее, я не могу заставить работать кнопку удаления. Это для внутреннего использования, поэтому я не очень беспокоюсь о внедрении SQL, поэтому структура базы данных создается без идентификатора в качестве первичного ключа. Таким образом, первое поле в таблице с именем common_name является уникальным, поэтому я использую его в качестве ссылки для кнопки удаления.
ридй-p.php:
<?php
//the following php code is for displaying the table contents on the same page
include 'config.php';
$query = 'select * from ReadMe';
$result = pg_query($query);
$i = 0;
// code for creating a table structure using css
echo '<html><body><style>
table, td, th {
border: 0.5px solid #D96B27;
text-align: left;
}
th, td {
padding: 10px;
} </style><table><tr>';
//fetching the column names of the db table
while ($i < pg_num_fields($result))
{
$fieldName = pg_field_name($result, $i);
echo '<th>' . $fieldName . '</th>';
$i = $i + 1;
}
echo '</tr>';
$i = 0;
//fetching and displaying the contents of the db table
while ($row = pg_fetch_row($result))
{
echo "<tr>";
$count = count($row);
$y = 0;
while ($y < $count)
{
$c_row = current($row);
echo '<td>' . $c_row . '</td>';
next($row);
$y = $y + 1;
}
// Adds the Edit and Delete buttons to every row
echo "<form action=\"readme-p-delete.php?name=" . $row['name'] . "\" method=\"post\">";
echo "<input type='hidden' name='name' value=" . $row['name'] .">";
echo "<td><input type=\"submit\" style='color:#0090C1;' value=\"Edit\"></td>";
echo "<td><input type=\"submit\" name=\"submit\" value=\"Delete\" style='color:#E63462;'></form></td></tr>";
$i = $i + 1;
}
pg_free_result($result);
echo '</table></body></html>';
//Delete button function
?>
ридй-р-delete.php:
<?php
include 'config.php';
sql = "DELETE FROM readme WHERE common_name='$_POST[name]'";
$result = pg_query($sql);
pg_free_result($result);
header('location: readme-p.php');
?>