I have a code which should delete a selected ID row from table by loading a remove.php file with SQL query. The problem is that it doesn't work but I get no errors or notices. My variable seems to get transfered to remove.php in URL just fine, as '<a href="remove.php?='.$Fvalue.'">'
gets interpreted as
remove.php?=1
for example, where 1 is primary id of the row.
Here is all the code related to the question only:
EDIT:
Rendered HTML for products table with REMOVE button:
<!-- Products table -->
<table class="table">
<thead>
<tr>
<th scope='col'>id </br ></th><th scope='col'>name </br ></th><th scope='col'>price </br ></th><th scope='col'>amount </br ></th><th scope='col'>category_name </br ></th> </tr>
</thead>
<tbody>
<tr><td data-id="1"><a href="remove.php?remove_id=1"> REMOVE</a></td>
<td>iPhone 7</td>
<td>800</td>
<td>15</td>
<td>Smartphones</td>
</tr><tr>
<td data-id="42"><a href="remove.php?remove_id=42"> REMOVE</a></td>
<td>Motorola </td>
<td>3000</td>
<td>5</td>
<td>Smartphones</td>
</tr><tr><td data-id="2"><a href="remove.php?remove_id=2"> REMOVE</a></td><td>Macbook Pro 2015</td>
<td>1300</td><td>10</td>
<td>Computers</td></tr><tr><td data-id="4"><a href="remove.php?remove_id=4"> REMOVE</a></td>
<td>Dell XPS</td>
<td>1400</td>
<td>6</td><td>Computers</td>
</tr><tr><td data-id="41"><a href="remove.php?remove_id=41"> REMOVE</a></td>
<td>CHROMEBOOK</td>
<td>5600</td>
<td>8</td>
<td>Computers</td></tr></tbody>
Updated PHP:
<?php
foreach ($newArray as $value) {
echo '<tr>';
foreach ($value as $key => $Fvalue) {
$remove = $value['id'] = " REMOVE";
if($value[$key] == $value['id']) {
echo '<td data-id="'.$Fvalue.'">' . '<a href="remove.php?remove_id='.$Fvalue.'">' . $remove . '</a>' . '</td>'; // will show all values.
} else {
echo '<td>' . $Fvalue . '</td>';
}
}
echo '</tr>';
}
?>
remove.php
<?php
require_once ("navigation.php");
require_once("database_connection.php");
$id = !empty($_GET['remove_id']) ? $_GET['remove_id'] : null;
if($id != null) {
$deleteProducts = "DELETE FROM `products` WHERE `id` = '.$id.'";
mysqli_query($dbc, $deleteProducts);
}
Looking for any help to me spot any problems as I get no errors and have no idea why the code is not deleting a row in the table. Thanks.