title: When i click on ok on javascript alert dialog the page refreshed and alll the data inputed in the textbox will be blank
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;?php
  
    include "dbconfig.php";
    session_start();
    
  ?&gt;
  
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
   &lt;title&gt;Log in&lt;/title&gt;
   &lt;link rel="stylesheet" type="text/css" href="styles.css"&gt;
   &lt;link rel="stylesheet" type="text/css" href="bootstrap.css"&gt;
   &lt;link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet"&gt;
   &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"&gt;
   &lt;style type="text/css"&gt;
  
    .error
    {
     color: red;
     
  
    }
    .form-control
    {
     color: black;
    }
    .btn
  
    {
     color: white;
    }
  
    .panel
    {
     width: 340px; 
     margin-left: 350px;
     margin-top:50px;
    }
    .form-control
    {
     width: 300px;
    }
     .right-addon input { padding-right: 30px; }
     .right-addon .glyphicon { right: 10px;} 
   &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
     &lt;div class="container"&gt;
      &lt;div class="panel panel-info"&gt;
       &lt;div class="panel-heading"&gt;
        &lt;center&gt;&lt;strong&gt;&lt;h2&gt;Log in&lt;/h2&gt;&lt;/strong&gt;&lt;/center&gt;
       &lt;/div&gt;
       &lt;div class="panel-body"&gt;
       &lt;form method="post" role="form" id="login"  enctype="multipart/form-data"&gt;
        &lt;div class="form-group"&gt;
         &lt;input type="text" class="form-control" name="loginusername" placeholder="Username"&gt;
          
        &lt;/div&gt;
  
         
        &lt;div class="form-group "&gt;
        &lt;div class="inner-addon right-addon"&gt;
         
          &lt;input type="password" id="password" class="form-control" name="loginpassword" placeholder="Password"&gt;
           
  
        &lt;/div&gt;
        &lt;/div&gt;
  
        &lt;div class="form-group"&gt;
          &lt;h5&gt;&lt;a href="#"&gt;forgot password ?&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="#"&gt;issues while signing in ?&lt;/a&gt;&lt;/h5&gt;
        &lt;/div&gt;
  
        &lt;div class="form-group"&gt;
          &lt;input type="submit" class="form-control btn btn-primary" value="Log in" name="lgn"&gt;
        &lt;/div&gt;
  
        &lt;/form&gt; 
  
  
       &lt;/div&gt;
  
  
       &lt;div class="panel-footer"&gt;
        &lt;center&gt;Don't have an account?&lt;a href="sign_up.php"&gt;register&lt;/a&gt;&lt;/center&gt;
       &lt;/div&gt;
  
  
      &lt;/div&gt;
     &lt;/div&gt;
  
  
  
        &lt;!-- Jquery Plugin CDN --&gt;
  
  
       &lt;script src="http://code.jquery.com/jquery-3.3.1.min.js"
             integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
             crossorigin="anonymous"&gt;
            
         &lt;/script&gt;
  
  
           &lt;!-- Jquery Validation Plugin CDn --&gt;
  
         &lt;script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery-validation@1.17.0/dist/jquery.validate.js"&gt;
          
         &lt;/script&gt;
  
         
         &lt;!-- Linking Page to index.js for form validation --&gt;
  
         &lt;script type="text/javascript" src="index.js"&gt;
          
         &lt;/script&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  
  &lt;?php 
   
  
    
  
    
  
   if (isset($_POST["lgn"])) 
   {
    
  
          $result=mysqli_query($db,"select * from signup where semail='$loginusername' and screatepass='$loginpassword'"); 
  
  
          if ($loginusername=="admin@gmail.com" &amp;&amp; $loginpassword=="039218") {
  
           $_SESSION["session_admin"]=$loginusername;
           
           header("location:admin.php");
  
           
          }
          elseif (mysqli_num_rows($result)==1) {
          
           header("location:Home.php");
              
          }   
          else
          {
           
           echo "&lt;script&gt;alert('Invalid username or password')&lt;/script&gt;";
  
          }
  
  
   }
  
  
  
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I click on ok on javascript alert dialog the page refreshed and all the data entered in the textbox will be blank. How to overcome this problem? I don't want this, I want that the page should not be refreshed after click on OK on javascript alert. I also added image with this question.</p>
  
  <p><img src="https://i.stack.imgur.com/0cJdK.png" alt="enter image description here"></p>