Looked at a bunch of examples. Nothing happens. I try to transfer to the value of the ID of the input element. The row identifier from the database for subsequent deletion of the record. But no matter how I tried, Get does not take this value from id attribute
<?php
require_once("dbcontroller.php");
$db_handle = new DBController();
$sql = "SELECT * from main";
$faq = $db_handle->runQuery($sql);
?>
<table class="one">
<thead>
<tr>
<th class="table-header" width="10%">№</th>
<th class="table-header">Дата</th>
<th class="table-header">Адрес</th>
<th class="table-header" width="10%">Наименование проекта</th>
<th class="table-header">Что изменено</th>
<th class="table-header">Кем</th>
<th class="table-header">Документ</th>
</tr>
</thead>
<tbody>
<?php
foreach($faq as $k=>$v) {
?>
<tr class="table-row">
<td><?php echo $k+1; ?></td>
<td contenteditable="true" onBlur="saveToDatabase(this,'destination','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["destination"]; ?></td>
<td contenteditable="true" onBlur="saveToDatabase(this,'name_change','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["name_change"]; ?></td>
<td contenteditable="true" onBlur="saveToDatabase(this,'changee','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["changee"]; ?></td>
<td contenteditable="true" onBlur="saveToDatabase(this,'date_change','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["date_change"]; ?></td>
<td contenteditable="true" onBlur="saveToDatabase(this,'moderator','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["moderator"]; ?></td>
<td contenteditable="true" onBlur="saveToDatabase(this,'image1','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["image1"]; ?></td>
<td> <input type="submit" name="delete" value="Delete" onclick="location.href='delete.php'" id=''<?php echo $faq[$k]["id"]; ?>''></td>
</tr>
<?php
}
?>
</tbody>
</table>
it's all about this line
<td> <input type="submit" name="delete" value="Delete" onclick="location.href='delete.php'" id=''<?php echo $faq[$k]["id"]; ?>''></td>
delete.php
<?php
$id = $_GET['id'];
//Connect DB
//Create query based on the ID passed from you table
//query : delete where Staff_id = $id
// on success delete : redirect the page to original page using header() method
$dbname = "registration_change";
$conn = mysqli_connect("10.191.24.99", "asutp", "asutp", $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// sql to delete a record
$sql = "DELETE FROM main WHERE id = $id";
echo($sql);
if (mysqli_query($conn, $sql)) {
mysqli_close($conn);
header('Location: main-edit.php'); //If book.php is your main page where you list your all records
exit;
} else {
echo "Error deleting record";
}
?>