I need to check if a username and a password passed by another page are empty but this doesn't work and I can't understand why. Username and password are passed by a form in another page with POST method.
session_start();
if(!(isset($_SESSION['username'])) && !(isset($_SESSION['password']))){
$_SESSION['username']=trim($_POST['username']);
$_SESSION['password']=$_POST['password'];
}
[...]
$username = $_SESSION['username'];
$password = $_SESSION['password'];
if($username=="" || $password=="")
{
echo "<script>
alert('You need to fill all fields!');
window.location.assign('reg.php');
</script>";
}
Thanks.
Edit. Now with this:
if(is_null($username) || is_null($password))
{
echo "<script>
alert('You need to fill all fields!');
window.location.assign('reg.php');
</script>";
}
else
{
if(strlen($username)<5 || strlen($password)<5)
{
echo "<script>
alert('Fiels must be at least of 5 character!');
window.location.assign('reg.php');
</script>";
}
It jumps directly to the second error message, 'Fiels must be at least of 5 character!'. Why? Thanks.