-1

This is a delete query but I want to show the deleted data in the database. Please help me.

<?php
    require_once '../students.php';
    $admin_query = $mysqli->query("SELECT * FROM `students`") or die(mysqli_error());
    $admin_valid = $admin_query->num_rows;
    if($admin_valid == 1){
        echo '<script>alert("Error: Can\'t delete if only one applicant is available")</script>';
        echo '<script>window.location = "student_acc.php"</script>';
    }else{
        $mysqli->query("DELETE FROM `students` WHERE `students`.`student_id` = '$_REQUEST[student_id]'") or 
        die(mysqli_error());
        header('location:student_acc.php');
    }
?>
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • So put a flag on your students table like `deleted` then `UPDATE students SET students.deleted = 1 WHERE ...` ? Of course, if you get a GDPR *"right to be forgotten"* request you have to *really* delete the student data. – CD001 May 21 '19 at 08:03
  • How would you show data that is no longer there? – Markus Deibel May 21 '19 at 08:04

2 Answers2

2

First of all, please take a look at How can I prevent sql injection in PHP?. Your code is heavily prone to SQL injection which means that someone could gain unauthorized access to your SQL database.

Secondly, add a column in your database named disabled or similar. Do an update query like the following:

UPDATE `students` SET `disabled` = 1 WHERE `student_id` = YOUR_STUDENT_ID

On all you future checks for students, just filter out where students have disabled = 1.

Matt
  • 2,851
  • 1
  • 13
  • 27
0

What I can suggest is to make another table where the idea is you will put into archives the data you have deleted

It's like a temporary graveyard for your deleted data, though it is still in your database, but at least you will have a copy of your previous records

This is the best practice in companies, we don't literally delete records / data

So to wrap up

STEP 1

You delete your data in your main table

STEP 2

retrieve that data and insert it in your archives table

Suomynona
  • 639
  • 1
  • 5
  • 20