This is a problem that I've had for a few days now. When I do
<form action = "something.php" method="post">
It always works, but when I try to switch this up in PHP with header I have a few problems. What I am trying to do is check if the input data is written in, if not then echo a certain phrase but if everything is written in then log in.
<?php
$usernameErr = $passwordErr = "";
if (isset($_POST['submit'])) {
if(empty($_POST["uid"])){
$usernameErr = "Username required";
};
if(empty($_POST["pwd"])){
$passwordErr = "Password required";
} ;
if(!empty($_POST["uid"]) and !empty($_POST["pwd"])) {
header("Location: login.php");
};
};
?>
<form name="frm" method="post">
<input type = "text" name = "uid" placeholder = "Username"; >
<?php echo $usernameErr; ?> <br>
<input type = "password" name = "pwd" placeholder = "Password" ; >
<?php echo $passwordErr?> <br>
<input name="submit" type="submit" id="submit" onclick="action()" value="submit" >
</form>
<?php
if (isset($_SESSION['id'])){
echo $_SESSION['id']," ", "You've succesfully logged in";
} else {
echo "youre not logged in";
}
?>