title: Popup window to display result from php with javascript
body: <p>I'm trying to implement javascript to display result from php. </p>
  
  <p>Basically, I have a login page. For fail login, instead of just echoing them with php, I want the result to be display in a popup. </p>
  
  <p>I try to implement the alert box but looks like I miss something.</p>
  
  <p>Successful login will be redirect to <code>logged.php</code> and will display the details of <strong>UserName</strong> and <strong>LoginStatus</strong>.</p>
  
  <p>If the login failed, since I'm using stored procedure the <code>LoginStatus</code> will automatically displayed the error message of the fail operation.</p>
  
  <p>Here's my full code <a href="https://jsfiddle.net/2dqmuc87/" rel="nofollow noreferrer">fiddle</a></p>
  
  <p>This is my login page. </p>
  
  <p>login.php</p>
  
  <pre><code>$stmt=odbc_exec($conn,"CALL UserLogin (".$_POST['UserId'].",'".$_POST['UserPwd']."','".$_POST['ModuleCd']."','".$_POST['SubModuleCd']."')");
  
  if (!$stmt)
  {
  "Error : " . odbc_errormsg();
  }
  
  if (odbc_fetch_row($stmt))
  {
  
  $Username=odbc_result($stmt,"Username");
  $LoginStatus=odbc_result($stmt,"LoginStatus");
  }
  
  /*Succesful Login*/
  if ($LoginStatus==1)
  {
  
  $_SESSION["Username"]=$Username;
  $_SESSION["LoginStatus"]=$LoginStatus;
  header("Location: logged.php");
  }
  
  else
  
  /*Fail Login*/
  echo $Username=odbc_result($stmt,"Username");
  echo $LoginStatus=odbc_result($stmt,"LoginStatus");
  </code></pre>
  
  <p>html :</p>
  
  <pre><code>&lt;form method="post" name="login"&gt;
    &lt;input type="text" name="UserId" value=""&gt;
    &lt;input type="password" name="UserPwd" value=""&gt;
    &lt;input type="submit" name="login" value="Login"&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>javascript :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type="text/javascript"&gt;
       /*message of fail login*/
              function show_alert() {
                  if (LoginStatus != 1) {
                      alert(LoginStatus);
                  }
      
      
              &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Any suggestion? </p>