title: How to show div in if block in php
body: <p>I have index.php, in index.php there is a login form with session. If username and password are correct, it would go to home.php. But if username or password is incorrect I want to show div above login form that contains an error message like this <img src="https://i.stack.imgur.com/bPsLU.jpg" alt="Error Message">. </p>
  
  <p>I want this warning div is hidden and it will be shown only if username or password is incorrect. I've tried some other solution but none of them work, first If I put div in else condition, it will appear above login form no matter what the condition are. Second, if I put javascript to change style display = block, it won't appear in index page. Please help me to solve this problem. Thanks.</p>
  
  <p><strong>Index.php</strong></p>
  
  <pre class="lang-html prettyprint-override"><code>       &lt;?php
            session_start();
            if(isset($_POST['login']))   
            {
              $user = $_POST['user'];
              $pass = $_POST['pass'];
              if($user == "admin" &amp;&amp; $pass == "admin") 
              {                                      
                $_SESSION['user']=$user;
              ?&gt;
                &lt;script language="javascript"&gt;window.location.href='home.php' &lt;/script&gt;
              &lt;?php
              } else {
              //What should I do here?                
              ?&gt;
                &lt;script language="javascript"&gt;document.getElementById("warning").style.display = "block" &lt;/script&gt;
              &lt;?php
              }
            }
          ?&gt;
  
          &lt;!-- Warning that I want to show if username or password is incorrect --&gt;
          &lt;div id="warning" class="w3-container w3-red w3-text-white w3-card-2 w3-animate-opacity" style="position: relative;margin-top: 20px;display:none"&gt;
              &lt;span onclick="this.parentElement.style.display='none'" class="w3-closebtn"&gt;&amp;times;&lt;/span&gt;
              &lt;strong&gt;Warning!&lt;/strong&gt; Incorrect Username or Password!
          &lt;/div&gt;
          &lt;!-- Login form --&gt;
          &lt;form class="w3-container" action="" method="post"&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p><strong>[EDIT]</strong></p>
  
  <p>I finally solved the problem by following Sharky's suggesstion to put php code below warning div. In else case I'm still using javascript that will change style display of warning div to block. Thanks for all your help :)</p>