I believe you could do this:
if (isset($_GET["delete"])) {
mysqli_begin_transaction($connection); // Using transactions.
// Execute log insertion first.
$stm_log = mysqli_prepare($connection, "INSERT INTO item_management_log (item_code_id, item_name, deleted_stock) VALUES (?, ?, ?)");
$log_message = "deleted $item_name from the stock";
mysqli_stmt_bind_param($stm_log, "iss", $item_code_id, $item_name, $log_message);
mysqli_stmt_execute($stm_log);
// Remove the item later.
$stm_delete = mysqli_prepare($connection, "DELETE FROM item_management WHERE item_management_id = ?");
$the_item_management_id = $_GET["delete"];
mysqli_stmt_bind_param($stm_delete, "i", $the_item_management_id);
mysqli_stmt_execute($stm_delete);
if (mysqli_stmt_affected_rows($stm_delete) > 0) {
mysqli_commit($connection);
} else {
mysqli_rollback($connection); // Undo everything if nothing was deleted.
}
header("Location:inventory_management.php");
}
Why Transactions
You should use transactions because you probably want to log something that actually happened, and so you can abort (through rollback) recording the log if there is an error deleting the item. This way, you won't have an inaccurate log in the database.
Note
I also used mysqli_stmt_affected_rows
which makes it possible to know the number of affected records and thus know if an item was really deleted or not.
Also, I believe you should use PDO instead of mysqli, which is a friendlier api. Or at least you should use the mysqli's object-oriented style, which will make your code cleaner and easier to understand.