title: PHP Post Automatically Firing On Page Load?
body: <p>I am making a simple PHP login with POST. However, every time I load the page, the function gets fired before I even hit submit on the html form. I have tried the method below and isset($_POST['submit']) but both ways are firing every single time I load the page. How do I stop this from occuring? Thank you.</p>
  <pre><code>//PHP CODE ABOVE HTML
  
      &lt;?php
      
      $serverName = &quot;localhost&quot;;
      $dBUserame = &quot;blake&quot;;
      $dBPassword = &quot;password&quot;;
      $dBName = &quot;database&quot;;
      
      session_start();
      
      $conn = mysqli_connect($serverName, $dBUserame, $dBPassword, $dBName);
      
      // Check connection
      if ($conn-&gt;connect_error) {
          die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);
      }
      
      
      if ($_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;) {
      
          $email = mysqli_real_escape_string($conn, $_POST['email']);
          $password = mysqli_real_escape_string($conn ,$_POST['password']);
      
              $sql = &quot;SELECT * FROM users WHERE email = '$email' AND password = '$password'&quot;;
      
              $result = $conn-&gt;query($sql);
      
              if ($result-&gt;num_rows &gt; 0) {
      
                  $_SESSION['useremail'] = $email;
      
                  header('Location: https://allevohealth.com/admin/newsletter/contacts.php');        
      
                  // output data of each row
      
                  while ($row = $result-&gt;fetch_assoc()) {
      
                     $_SESSION['name'] = $row[&quot;fullname&quot;];
      
                     $_SESSION['email'] = $row[&quot;email&quot;];
      
                     $_SESSION['useridid'] = $row[&quot;id&quot;];
      
                     echo &quot;&lt;br&gt; Full Name: &quot;. $row[&quot;fullname&quot;]. &quot; - Email: &quot;. $row[&quot;email&quot;]. &quot; &quot; . $row[&quot;passsword&quot;] . &quot;&lt;br&gt;&quot;;
      
                  }
              } else {
      
                  echo &quot;0 results&quot;;
              }
      
              $conn-&gt;close();
      }
      
      ?&gt;
  
  
  //HTML CODE BELOW PHP
  
                  &lt;div class=&quot;col-lg-12 row justify-content-center&quot;&gt;
                      &lt;div class=&quot;col-lg-4 col-md-8 col-sm-9 mb-5&quot;&gt;
                          &lt;div class=&quot;p-5&quot; style=&quot;border-radius: 20px !important; background-color: #161621&quot;&gt;
                              &lt;form id=&quot;myform&quot; method=&quot;post&quot;&gt;
                                  &lt;h2 class=&quot;h4 text-white mb-5&quot;&gt;ACCOUNT LOGIN&lt;/h2&gt;
                                  &lt;div class=&quot;row form-group&quot;&gt;
                                      &lt;div class=&quot;col-md-9&quot;&gt;
                                          &lt;label class=&quot;text-white&quot; for=&quot;email&quot;&gt;EMAIL&lt;/label&gt;
                                          &lt;input type=&quot;email&quot; id=&quot;input-email&quot; name=&quot;email&quot; class=&quot;form-control rounded-0&quot;&gt;
                                          &lt;p id=&quot;result&quot; style=&quot;padding-top: 2%; font-weight: bold;&quot;&gt;&lt;/p&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;div class=&quot;row form-group&quot;&gt;
                                      &lt;div class=&quot;col-md-7 mb-3 mb-md-0&quot;&gt;
                                          &lt;label class=&quot;text-white&quot; for=&quot;password&quot;&gt;PASSWORD&lt;/label&gt;
                                          &lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;input-password&quot; class=&quot;form-control rounded-0&quot;&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;div class=&quot;row form-group&quot;&gt;
                                      &lt;div class=&quot;col-md-12&quot; style=&quot;padding-top: 5%&quot;&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;LOGIN&quot; style=&quot;width: 150px&quot; class=&quot;btn btn-primary mr-4 mb-2&quot;&gt;
                              &lt;/form&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  </code></pre>