html - PHP validate executes the IF statement AND the ELSE statement at the same time -


like title says, i'm having problem regarding validation php. it's simple login php, if user inputs wrong information, validation form execute saying return previous login page after 5 seconds countdown. but, if user inputs right username , password, display welcome text on validation php. however, whenever run program executes both welcome text , countdown, regardless of whether inputted information right or wrong.

here's first php:

<!doctype html public"-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>     <style>         body {         margin:0;          font-family: calibri}          .style1 {         color: #ffffff}      </style> </head> <body>     <h1>getting input user</h1><h2>example 1</h2>     <form method="post" action="validatea.php">     <table width="200" border="0" cellspacing="0" cellpadding="5">         <tr>             <th bgcolor="#006699" scope="row"><span class="style1">username</span></th>             <td><label>             <input type="text" name="txtusername" id="txtusername" required="required"/>             </label></td>         </tr>          <tr>             <th bgcolor="#006699" scope="row"><span class="style1">password</span></th>             <td><label>             <input type="password" name="txtpassword" id="txtpassword" required="required"/>             </label></td>         </tr>          <tr>             <th colspan="2" scope="row"><div align="right">             <input type="reset" value="clear"/>             <input type="submit" value="login"/>             </div></th>         </tr>         </table>         </form>         <hr/>   </body> </html> 

here's validation php:

<!doctype html> <html> <head> <meta charset="utf-8"> <title>untitled document</title>      <script>         var ctr=5;         function countdown(){             window.document.getelementbyid("cnt").innerhtml=ctr;             ctr--;             if (ctr<0) window.location="samplea.php";             settimeout("countdown()", 1000);         }         </script>  </head>  <body>  <?php     if(isset($_post["txtusername"])){         $uname="user";$psw="hello";             if($uname==$_post["txtusername"] && $psw==$_post["txtpassword"]){                 echo "<h2>welcome " .$_post["txtusername"]."!</h2>";             else{                 echo"username , password invalid.<br/><br/>";                 echo'this redirect login form in <label id="cnt"></label>seconds...';                 echo'<script> countdown();</script>';             }         }     } ?>  </body> </html>  

you missplaced } in second if

<?php     if(isset($_post["txtusername"])){         $uname="user";$psw="hello";         if($uname==$_post["txtusername"] && $psw==$_post["txtpassword"]){                 echo "<h2>welcome " .$_post["txtusername"]."!</h2>";         }else{ //forgot close if }                 echo"username , password invalid.<br/><br/>";                 echo'this redirect login form in <label id="cnt"></label>seconds...';                 echo'<script> countdown();</script>';         }     } ?> 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -