title: My PHP fopen() fails to read the final line?
body: <p>I have an account system that reads info from a file. These include (in order) username, password, email, bio, reputation. But for some reason (when I load the data with a series of fgets()) It returns the following error: </p>
  
  <blockquote>
    <p>Warning: fgets() expects parameter 1 to be resource, null given in /home/dsgamesr/public_html/lualessons.x10host.com/userpage.php on line 95.</p>
  </blockquote>
  
  <p>I made sure that $rep was an item in  the text file. The program proceeds but still resets the $rep variable (and saves it as) blank. The code is as follows:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php 
  
      if (isset($_POST['button1'])) 
      {
          $file=fopen("Users/user".$_SESSION['Username'].".txt","r");
          $user=trim(fgets($file));
          $pass=trim(fgets($file));
          $email=trim(fgets($file));
          $bio=trim(fgets($file));
          $rep=fgets($files);
  
          fclose($file);
          echo $rep;
  
          $nfile=fopen("Users/user".$user.".txt","w");
          fwrite($nfile,$user."\n");
          fwrite($nfile,$pass."\n");
          fwrite($nfile,$email."\n");
          fwrite($nfile,$_POST['bio']."\n");
          fwrite($nfile,$rep."\n");
          echo'Bio succesfully updated';
          //echo $user;
  
      }
  
  ?&gt;
  </code></pre>
  
  <p>There is a total of five lines before I submit the new bio and a total of 5 with the final line blank after I submit it. </p>