PHP login validation when user is not active -
i developed php login system when user logs in , account still not activated admin display message2
, if user inputs wrong credentials display mesage1
i done work. confused on why condition falls under message1
.
here code.
<?php session_start(); if(isset($_post["submit"])){ // windows // $servername = "localhost"; // $username = "root"; // $password = ""; // $dbname = "logindb"; // linux $servername = "localhost"; $username = "root"; $password = "gmg0ddepfrxs"; $dbname = "logindb"; // create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // check connection if (!$conn){ die("connection failed: " . mysqli_connect_error()); } $uname = $_post["name"]; $password = $_post["pwd"]; $sql = "select * user user_name='$uname' , password='$password'"; $result = mysqli_query($conn, $sql); while($row = mysqli_fetch_assoc($result)){ $utype = $row["user_type"]; //1 $status = $row["user_status"]; //0 $username = $row["user_name"]; //username $password = $row["password"]; //password ng user } if (mysqli_num_rows($result) > 0 , $utype == '1'){ // session_start(); $_session["login"] = "access"; setcookie("name",$uname,false); echo "<script>window.location.href=\"member.php\"</script>"; }elseif (mysqli_num_rows($result) <= 0) { echo "<script>window.location.href=\"index.php?msg=1\"</script>"; }elseif ($utype == '0') { echo "<script>window.location.href=\"index.php?msg=2\"</script>"; } } ?>
here html code.
<html> <form action='login.php' method="post"> <table cellspacing='5' align='center'> <tr> <td>username:</td> <td> <input required type='text' name='name' /> </td> </tr> <tr> <td>password:</td> <td> <input required type='password' name='pwd' /> </td> </tr> <tr> <td></td> <td> <input type='submit' name='submit' value='submit' /> </td> </tr> </table> <?php if(isset($_get[ "msg"])){ $errmsg=$ _get[ "msg"]; if($errmsg==1 ){ echo "<div style='text-align: center;'><h5> <font color = \"red\ "> incorrect username and/or password! have registered? </font></div>"; } elseif ($errmsg==2 ) { echo "<div style='text-align: center;'><h5> <font color = \"red\ "> contact admin activate account. </font></div>"; } } ?> </form> <div style="text-align: center;"> <a href="register.php"> <button>register here</button> </a> </div> </html>
use simple header location redirect users:
<?php session_start(); if(isset($_post["submit"])){ $servername = "localhost"; $username = "root"; $password = "gmg0ddepfrxs"; $dbname = "logindb"; // create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // check connection if (!$conn){ die("connection failed: " . mysqli_connect_error()); } $uname = $_post["name"]; $password = $_post["pwd"]; $sql = "select * user user_name='$uname' , password='$password'"; $result = mysqli_query($conn, $sql); $row = mysql_fetch_assoc($result); $totalrows_result = mysql_num_rows($result); if ($totalrows_result == 0) { header("location: index.php?msg=1");} $utype = $row["user_type"]; //1 $status = $row["user_status"]; //0 if ($utype == '1'){ $_session["login"] = "access"; setcookie("name",$uname,false); header("location: member.php"); } else { header("location: index.php?msg=2"); } } ?>
Comments
Post a Comment