Advertisement
Guest User

Untitled

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