I have a problem. I am building my own login page and i have some troubles. When i test my page and I insert invalid username and password code works great. But when I insert data that exists in database it just skips the if(isset($_POST['but_submit'])) part. What could be wrong here?
Here's my code:
PHP:
<?php include ("config.php");
if(isset($_POST['but_submit'])){
$uname = mysqli_real_escape_string($con,$_POST['txt_uname']);
$password = mysqli_real_escape_string($con,$_POST['txt_pwd']);
if ($uname != "" && $password != ""){
$sql_query = "select count(*) as cntUser from users where Username='".$uname."' and passwrd='".$password."'";
$result = mysqli_query($con,$sql_query);
$row = mysqli_fetch_array($result);
$count = $row['cntUser'];
if($count > 0){
$_SESSION['uname'] = $uname;
header('Location: welcome.php');
}else{
echo "Invalid username and password";
}
} }
?>
HTML
<div class="container">
<form method="post" action="">
<div id="div_login">
<h1>Login</h1>
<div>
<input type="text" class="textbox" id="txt_uname" name="txt_uname" placeholder="Username" />
</div>
<div>
<input type="password" class="textbox" id="txt_uname" name="txt_pwd" placeholder="Password"/>
</div>
<div>
<input type="submit" value="Submit" name="but_submit" id="but_submit" />
</div>
</div>
</form>
</div>
I would be really happy somebody could help me :) Thank you!