fabi0

Delete record

Sep 21st, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4. $id = (int) $_GET['id'];
  5. $file = file('data.txt');
  6. if ($id > 0) {
  7.     for ($i = 0; $i < count($file); $i++) {
  8.         $exp = explode('@', $file[$i]);
  9.         if ($exp[0] == $id) {
  10.             $reWrite = 1;
  11.             unset($file[$i]);
  12.             break;
  13.         }
  14.     }
  15. }
  16.  
  17. if ($reWrite == 1) {
  18.     file_put_contents('data.txt', "");
  19.     foreach ($file as $value) {
  20.         file_put_contents('data.txt', $value, FILE_APPEND);
  21.     }
  22.     $_SESSION['_success'] = 'Записът е изтрит !';
  23.     header("Location: index.php");
  24. } else {
  25.     $_SESSION['_error'] = 'Не съществува такъв запис!';
  26.     header("Location: index.php");
  27. }
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment