简体   繁体   中英

How to Capture $_SESSION NAME that perform delete into oracle history table

I have a crud system using Oracle DB to store the data. There are two tables (the main table and history ). Users have to login to the system. I already created an update or delete trigger from main to the history table, and it works fine for both. Now I want to capture $_SESSION NAME and insert it into column ACTION_BY in table HISTORY when the user deletes any row. I have no idea how to do it. Can anyone help me.


proc_delete.php

<?
require 'inc_instance.php';

$id  = $_POST["id"];

$user = $_SESSION['name'];

$db = Database::obtain(HDBUSER, HDBPASS, HDBNAME);
$db->connect();

$sql = "DELETE FROM CIM_TRACKING_MAIN WHERE id = '".$id."'";
$db->query($sql);

echo json_encode([$id]);

$db->close();

Can I directly insert session name into the history table when the user pushes the delete button?

This is how it looks:

图片

Not sure is this the thing you want

$query = $db->query($sql);
if($query){ // return true if your delete query success
// Insert query into your History table here
   $sql_02 = "INSERT INTO History(ACTION_BY) VALUES ('$user')";
   if($db->query($sql_02)=== TRUE){
    // do the action you want here, if no need then remove this if statement
 }
}

But using this will cause major security vulnerability , try to use prepare statement next time

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM