Login form using PHP, Problem in isset function, [duplicate]

  html, mysql, php

I was trying to write a simple login form (no security added) but it’s doing nothing when I submit.
First of all my database name=test in this, there is a table name "login" and two head UserName and PW. The database connection is successful but when i trying to find the variable with isset it is not working. Thanks.

Main problem:

   if (isset($_POST['un'])){
    something;
    }
    else{
    echo"database error";
//excuting this block instead upper if block;
}




<?php
include ('config.php');

if (isset($_POST['un'])){
    $status="paichi";
    $user= $_POST['un'];
    $pw = $_POST['pw'];
  //  $sql="select * from login where UserName='".$user."' AND pw='".$pw."'limit 1";

    $result= mysqli_query($db,"SELECT * from login where UserName= '".$user."' AND PW= '".$pw."'");


    if((mysql_num_rows($result))==true)
    {
        echo"you have logged in vai";
        exit();
    }
    else
    {
        echo"problem problem";
    }
}
else
{
    echo"database error";
}

?>

<html>

<head>
    <title>Login Page</title>



</head>

<body>

<div>
    <div >
        <b>Login</b></div>

        <div>

            <form action = "#" method = "POST">
                <label for="username">UserName :</label>
                <input type = "text" name = "un" class = "box"/><br /><br />
                <label for="password">Password  :</label>
                <input type = "password" name = "pw" class = "box" /><br/><br />
                <input type="submit" value = " Submit "/><br />
            </form>

            <div><?php echo $status; ?></div>

        </div>

    </div>

</div>

</body>
</html>

when running the server it’s showing database error that i tried to find with else condition if isset function doesn’t work.

Source: Ask PHP

LEAVE A COMMENT