0

I want to save the data to another table in the database when successfully deleted

Here is my delete.php code

if(isset($_POST["id"]) && !empty($_POST["id"])) {

    $sql = "DELETE FROM client_info WHERE id = ?";
    if($stmt = mysqli_prepare($conn, $sql)) {
        mysqli_stmt_bind_param($stmt, "i", $param_id);
        $param_id = trim($_POST["id"]);
        if(mysqli_stmt_execute($stmt)) {
           
        }
    } 
} else {

    if(empty(trim($_GET["id"]))) {

    }
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Dan
  • 1
  • 2
  • Why is this tagged bootstrap-5? – Gert B. Jan 26 '22 at 12:57
  • 2
    My first question is, why do you want to save it to another table? I would suggest using soft deletes instead. The data stays in the same table, you don't actually delete it, but set a column `deleted` to `1`. That way you can keep the log, and restoring a row will be easy. – Gert B. Jan 26 '22 at 13:01
  • 1
    First, issue an _insert_ statement. Then do your _delete_. Do both within a _transaction_. – waterloomatt Jan 26 '22 at 13:01
  • As mentioned before best solution is to soft delete the data, but if you want to move it to another table I would create a database trigger on delete statements for that table – Ebski Jan 26 '22 at 13:08
  • what if i make another query? because i want to display the data in another form – Dan Jan 26 '22 at 13:28
  • You can show it in "another form", no need to put it in another table – Gert B. Jan 26 '22 at 13:33

0 Answers0