title: PHP if else statements error check
body: <p><strong>I am editing this to clarify my question. users input a membername and displayname in a form, and the php looks for the membername in a list to match against, then edits the display name when successfully finding it with the user's input.</strong></p>
  
  <p>membernames and usernames are stored in the file like:</p>
  
  <pre><code>membername=displayname
  </code></pre>
  
  <p><strong>This code works, except if they mistype their membername (meaning it doesn't match what is in the file), <em>it still redirects to the success page</em>, however it does not change the file (as it shouldn't).</strong></p>
  
  <p>What I need is to display an error page when they type in a membername that does not match, however I cannot get it to work.</p>
  
  <pre><code>&lt;?
  $fileurl = '/../../.../..../memberfiletest';
  
  $membername = $_POST['membername'];
  $displayname = $_POST['displayname']; 
  
  $file = file($fileurl, FILE_IGNORE_NEW_LINES); // Get file as array of lines
  
  foreach ($file as $n =&gt; $line) {
  $parts = explode('=', $line);
  if ($parts[0] == $membername) {
      $file[$n] = $membername . '=' . $displayname;
  }
  }
  file_put_contents($fileurl, implode("\n", $file)); // Put file back together
  $success_page = 'http://example.com/.../private.php';
  header('Location: '.$success_page);
  ?&gt;
  </code></pre>
  
  <p><strong>edited coding that I've tried</strong> : Using this coding below I've attempted to use it as is and modifying it. If I put in an error page to use a redirect it goes to the error page whether the script runs or not. On successful change it never redirects to google (using google just as a test).</p>
  
  <pre><code>&lt;?
  $fileurl = '/.../..../...../...../memberfiletest';
  
  $membername = $_POST['membername'];
  $displayname = $_POST['displayname']; 
  
  $file = file($fileurl, FILE_IGNORE_NEW_LINES); // Get file as array of lines
  
  foreach ($file as $n =&gt; $line) {
  
  $parts = explode('=', $line);
  if ($parts[0] == $membername) {
  
      $file[$n] = $membername . '=' . $displayname;
      //write the contents and redirect here itself
      file_put_contents($fileurl, implode("\n", $file));
      $success_page = 'http://google.com';//simply redirecting to google if its true
      header('Location: '.$success_page);
  } 
  else {//throw an error
      //use this 
      $flag = 1;
  }
  
  if(isset($flag)){
      //die("Membername not found");
      header('Location:'.$error_page);
  }
  }
  ?&gt;
  </code></pre>