Why is updating in DELETE trigger delayed when fetching user?

Joined
Mar 25, 2023
Messages
1
Reaction score
0
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);

}

?>
 
Joined
Sep 4, 2022
Messages
128
Reaction score
16
you use $extract_id .. but what is its value ?

you have to debug all your code :
var_dump($var) ; ///and
print_r($var) // will help you to achieve debug

you can COUNT how many values are in a array $result with count($array)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top