I have this DELETE Trigger in my PHP where I can fetch the current user who deleted the record. The problem is that when I deleted a record the current user who deleted is not updating. It takes two delete trigger before fetching the current user.
PHP:
<?php
require '../config.php';
if(!empty($_SESSION["id"])){
$id = $_SESSION["id"];
$result = mysqli_query($conn, "SELECT * FROM tb_user WHERE id = $id");
$row = mysqli_fetch_assoc($result);
}
$name = $row['name'];
$query = "DELETE FROM tb_inventory WHERE id IN($extract_id);";
$query .= "DROP TRIGGER IF EXISTS `DELETE`;
CREATE DEFINER=`root`@`localhost` TRIGGER `DELETE` AFTER DELETE ON `tb_inventory`
FOR EACH ROW INSERT INTO inventory_history
VALUES(null, OLD.tag, OLD.hardware, OLD.model, OLD.status, OLD.agency, 'DELETED', '$name', NOW());";
$query_delete = mysqli_multi_query($conn, $query);
}
?>