title: Data in text file gets erased on form submit click
body: <p>For a website, the user should be able to type a title and post in a form and press a submit button to enter them. Upon pressing the submit button, the data in the forms are written to their assigned text files which are in the same folder as the webpage. The writing works fine, but as you can see below, I have attempted to make it so that if the user clicks the submit button without one of the two fields (or neither of the fields) being filled in the site will prompt them to enter text and no file writing takes place.</p>
  
  <p>My issue is that when they click submit and a field isn't filled, this will actually affect the .txt files and they will also end up blank. I want the files to retain their 'old' text unless both textareas in the form contain data to be overwritten. For example, if both .txt files have text in them and I click submit on the form with no text in the form, the two .txt files will keep their text instead of being overwritten to have no text (which is what currently happens).</p>
  
  <p>Here's the html and php:</p>
  
  <pre><code>&lt;form action="AdminBlog.php" method="post"&gt;
      Blog Title:&lt;textarea type="text" name="titleInput"&gt;&lt;/textarea&gt;&lt;br&gt;&lt;br&gt;
      Blog Post:&lt;textarea type="text" name="postInput"&gt;&lt;/textarea&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
      &lt;input type="submit" value="Submit"/&gt;
  &lt;/form&gt;
  
  
  &lt;?php
  $titleFile = fopen("Title.txt","w");
  
  $blogTitle = null;
  
  $postFile = fopen("Post.txt","w");
  
  $blogPost = null;
  
  
  if(!empty($_POST['titleInput']) &amp;&amp; !empty($_POST['postInput'])) {
  $blogTitle = $_POST['titleInput'];
  fwrite($titleFile,$blogTitle);
  fclose($titleFile);
  
  $blogPost = $_POST['postInput'];
  fwrite($postFile,$blogPost);
  fclose($postFile);
  }
  
  if (empty($_POST['postInput']) || empty($_POST['titleInput'])) {
  echo "Please enter a title and post.";
  }
  
  ?&gt;
  </code></pre>
  
  <p>Changing that final if statement to elseif or else didn't seem to make a difference. The echo is outputted when it should be, but the .txt files are still overwritten with no data (when a textarea is blank and user clicks submit).</p>
  
  <p>EDIT: Just wanted to add something. I'm not sure if this is relevant, but whether there is text in the files or not, I cannot read the text from another .php file. I can from this same one, but when trying to get the .txt file contents in another .php page, I cannot do so. This is also causing me a separate problem, just wanted to mention in case it was anything useful.</p>