My aim is for a user to click a button within a row to delete that row within the database.
The button is declared as so:
<td><button class="btn btn-default" onclick="removeStudent()" button id= <?php echo $productDetails["studentID"]; ?> type="button">Delete</button></td>
The remove function is as follows:
<script>
function removeStudent() {
$id = window.event.target.id.toString();
$sql = "DELETE FROM tableStudent WHERE studentID= '$id'" ;
if (mysqli_query($connection, $sql)) {
echo "Record deleted";
} else {
echo "Error deleting";
}
}
</script>
The webpage is connected to the database, and variable names are correct and working within other functions. Just delete function not working. Any help would be much appreciated.