title: serverside validation for a sign in form
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;form method="POST" onsubmit=" return formSubmit() " action="log-it-reports.php"&gt;
                  &lt;div class="userimage"&gt;
                      &lt;img class="userlogo" src="image/userlogo.png" alt="Picture- User Profile picture"&gt;
                  &lt;/div&gt;&lt;br&gt;
                  &lt;div class="error" id= "errorMsg"&gt;&lt;/div&gt;&lt;br&gt;
                  &lt;div class="error" id= "errorMsg1"&gt;&lt;/div&gt;
                   &lt;div class="field"&gt;
                      &lt;label class="stafflabel"&gt;  Staff Name  &lt;/label&gt;
                      &lt;input class="area" placeholder="staffmember or admin" onclick=" return userValidation()" onchange=" return userValidation()" id="staff" name="staffname" type="text" value="&lt;?php echo $staffname;?&gt;" &gt;
                   &lt;/div&gt; &lt;br&gt;
                   &lt;div class="error" id= "errorMsg2"&gt;&lt;/div&gt;
                   &lt;div class="field"&gt;
                      &lt;label class="passlabel"&gt;   Password    &lt;/label&gt;
                      &lt;input class="area" placeholder="password" onclick=" return userValidation()" onchange=" return userValidation()" id="pass" name="password" type="password" value="&lt;?php echo $password;?&gt;" &gt;
                   &lt;/div&gt;&lt;br&gt;
                  
                      &lt;div class="checkbox"&gt;
                         &lt;input type="checkbox" class="remember-me"&gt;
                         &lt;label class="remember" for="remember-me"&gt;Remember me         &lt;/label&gt;   
                         &lt;a class="pass-link" href="#"&gt; Forgot password?&lt;/a&gt;
                      &lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
                      
                   &lt;div class="field"&gt;
                      &lt;input class="btn" type="submit" value="Sign in"&gt;
                   &lt;/div&gt; &lt;br&gt;
                   &lt;div class="account-link"&gt;
                      Didn't create an account yet? &lt;a href="#"&gt;Create Account&lt;/a&gt;
                   &lt;/div&gt;
              &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>I would like to validate a sign in form with predefined usernames (admin, staffmember) and passwords (heretohelp!456 , letmein!123) in the serverside using php, my approach to it is using if statements to check for the posted input , firstly, is this a good approach or there is a better way to do it ? secondly, i'm getting an error in my code that says : syntax error, unexpected 'else' (T_ELSE)
  the brackets i have seem to match, the error shows in lines : 15, 32 of this snippet</p>
  <pre><code>&lt;?php
  
  $staffname = $_POST['staff'];
  $password = $_POST['pass'];
  $error = &quot;&quot;;
  
  // validating staff member:
  if (isset($_POST['submit'])) {
      if ($staffname == &quot;staffmember&quot;) {
          if ($password == &quot;letmein!123&quot;) {
              $error = &quot;&quot; ;
          }
          // redirect to the logs report page when successful
          header(&quot;location: log-it-reports.php&quot;);
          else {
              $error = &quot;* You have entered a wrong password!&quot;;
          }
      }
      else {
          $error = &quot;You have entered a wrong staff name!&quot;;
      }
  }
  
  // validating admin:
  if (isset($_POST['submit'])) {
      if ($staffname == &quot;admin&quot;) {
          if ($password == &quot;heretohelp!456&quot;) {
              $error = &quot;&quot; ;
          }
          // redirect to the logs report page when successful
          header(&quot;location: update-log-reports.php&quot;);
          else {
              $error = &quot;* You have entered a wrong password!&quot;;
          }
      }
      else {
          $error = &quot;You have entered a wrong staff name!&quot;;
      }
  }
  ?&gt;
  </code></pre>