title: Message displays before clicking on the submit button
body: <p>I am currently in the process of following a tutorial, the instructor in question has a form, when he clicks on the &quot;submit&quot; button without having entered any information, a message &quot;you must complete all fields&quot; is displayed. The problem is with me: I wrote the same code as him but the message appears at the start of the page loading, i.e. without even clicking on the submit button.</p>
  <p>By the way, he said that we'll use <code>$_SESSION[&quot;message&quot;]=null;</code> to not display that message when we load the form page.</p>
  <p><strong>Here is the session.php code</strong></p>
  <pre><code>&lt;?php
  
  session_start();
  function Message(){
      if(isset($_SESSION[&quot;message&quot;]))
      {
          $Output=&quot;&lt;div class=\&quot;message\&quot;&gt;&quot;;
          $Output .= htmlentities($_SESSION[&quot;message&quot;]);
          $Output .=&quot;&lt;/div&gt;&quot;;
          $_SESSION[&quot;message&quot;]=null;
          return $Output;
      }
  }
  ?&gt;
  </code></pre>
  <p><strong>And the user_registration.php code:</strong></p>
  <p>`</p>
  <pre><code>  &lt;?php require(&quot;include/session.php&quot;); ?&gt;
  &lt;?php require_once(&quot;include/database.php&quot;); ?&gt;
  
  &lt;?php 
  
  if(isset($_POST[&quot;submit&quot;])){
    $Username=mysqli_real_escape_string($Connection,$_POST[&quot;Username&quot;]);
    $Email=mysqli_real_escape_string($Connection,$_POST[&quot;Email&quot;]);
    $Password=mysqli_real_escape_string($Connection,$_POST[&quot;Password&quot;]);
    $ConfirmPassword=mysqli_real_escape_string($Connection,$_POST[&quot;ConfirmPassword&quot;]);
  
  }
  if(empty($Username)&amp;&amp;empty($Email)&amp;&amp;empty($Password)&amp;&amp;empty($ConfirmPassword)){
    $_SESSION[&quot;message&quot;]=&quot;All Fields must be filled out&quot;;
  
    
  }else if($Password!==$ConfirmPassword){
    $_SESSION[&quot;message&quot;]=&quot;Both passwords must be the same&quot;;
  
  }
  ?&gt;
  
  &lt;!DOCTYPE&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;
  Register Now
  &lt;/title&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;include/Styles.css&quot;&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;div&gt;&lt;?php echo Message(); ?&gt;&lt;/div&gt;
    
  &lt;div id=&quot;centerpage&quot;&gt;
      &lt;form action=&quot;./user_registration.php&quot; method=&quot;post&quot;&gt;
      &lt;fieldset&gt;
      &lt;span class=&quot;FieldInfo&quot;&gt;Username:&lt;/span&gt;&lt;br&gt;&lt;input type=&quot;text&quot; name=&quot;Username&quot; value=&quot;&quot;&gt;&lt;br&gt;
      &lt;span class=&quot;FieldInfo&quot;&gt;Email:&lt;/span&gt;&lt;br&gt;&lt;input type=&quot;email&quot; name=&quot;Email&quot; value=&quot;&quot;&gt;&lt;br&gt;
      &lt;span class=&quot;FieldInfo&quot;&gt;Password:&lt;/span&gt;&lt;br&gt;&lt;input type=&quot;password&quot; name=&quot;Password&quot; value=&quot;&quot;&gt;&lt;br&gt;
      &lt;span class=&quot;FieldInfo&quot;&gt;Confirme Password:&lt;/span&gt;&lt;br&gt;&lt;input type=&quot;password&quot; name=&quot;ConfirmPassword&quot; value=&quot;&quot;&gt;&lt;br&gt;
      &lt;br&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot;&gt;&lt;br&gt;
      &lt;/fieldset&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>`</p>