Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. <?php
  2. $file = "data.txt";
  3.  
  4. function get_data()
  5. {
  6.     global $file;
  7.     $data = "";
  8.     if( !file_exists($file) )
  9.     {
  10.         return $data;
  11.     }
  12.    
  13.     return file_get_contents($file);
  14.    
  15. }
  16.  
  17.  
  18. function add_new_item( $txt )
  19. {
  20.     global $file;
  21.     $data = get_data();
  22.     $data = $data . $txt . "<br>\r\n";
  23.    
  24.     $fp = fopen($file, "w");
  25.     fwrite($fp, $data );
  26.     fclose($fp);
  27. }
  28.  
  29. if( isset( $_POST['submit'] ) )
  30. {
  31.     $txt = $_POST['item'];
  32.     add_new_item( $txt );
  33. }
  34. ?>
  35. <form action="" method="post">
  36.     Name : <input type="text" name="item" />
  37.     <input type="submit" name="submit" value="Save" />
  38. </form>
  39.  
  40. <h3>All Data</h3>
  41.  
  42. <?php
  43. echo get_data();
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement