I have an inventory program I am working on and am wondering how to determine which button was clicked. The user sees a list of each item in their inventory, and next to each item there is a delete button. I am trying to figure out how to delete the specific item when the remove button next to it is clicked.
Here is the code that displays the inventory:
while ($row = mysqli_fetch_array($result)){
echo "<tr><td width='500px'>".$row['Name']."</td>";
echo "<td width='200px'><center><input type='Submit' value='Remove' name='".$row['Name']."'></center></td></tr>";
}
Here is what I have so far to remove the item:
if (isset($_POST['Submit'])) {
$Name = $_POST['name'];
$sql = "DELETE * FROM database WHERE Name = '$Name'";
if ($conn->query($sql) === TRUE) {
$message = "Successfully Removed " . $Name;
echo "<center><span style='color: red; font-size: 20px'><b>$message</b></span></center>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
mysqli_close($conn); //connection close
}