if ... else函数不起作用[关闭]

It echos "login not successful" with or without the userid and pwd being null and also when login with id:johntan, password niceday. It was supposed to be echo "login not successful" when userid and password is empty and also redirect it to another page when login with id:johntan, password niceday.

<?php 
if(!empty($_POST['userid'])){
$userid = $_POST['userid'];
}
else{
$userid = null; 
}
if(!empty($_POST['pwd'])){
$password = $_POST['pwd'];
}
else{
$password = null;
}
if($userid!=null && $password!=null){
if($userid=="johntan" && $password=="niceday"){
    header("location:fashionsummary.html");
}
else{
    $wronglogin = true;
}
}
?>
<?php 
if($wronglogin == true){
echo <<< <b><font color='red'>Login is not successful. Please try again</font></b>
;
}
?>

Use as follows :

if(!empty($_POST['userid'])){
    $userid = $_POST['userid'];
}
else{
    $userid = null; 
}
if(!empty($_POST['pwd'])){
    $password = $_POST['pwd'];
}
else{
    $password = null;
}
if($userid!=null && $password!=null){
    if($userid=="johntan" && $password=="niceday"){
        header("location:fashionsummary.html");
    }
    else{
        $wronglogin = true;
    }
}
?>
<?php 
if($wronglogin == true){
    echo "<font color='red'>Login is not successful. Please try again</font></b>";
}

It was because your echo line i.e

 echo <<< <b><font color='red'>Login is not successful. Please try again</font></b>

is giving error :

Parse error: syntax error, unexpected T_SL in E:\xampp\htdocs\testfolder\test1.php on line 25

You might have turned off the error reporting.

if($wronglogin == true){
   echo <<<EOF
   <b><font color='red'>Login is not successful. Please try again</font></b>
EOF;
}

According to Docs:

<<< After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation. The closing identifier must begin in the first column of the line.

Which you didn't observe.

I personally suggest giving an error message as well

if(!empty($_POST['userid'])){
   $userid = $_POST['userid'];
}else{
   $userid = null;
   echo 'Please fill in the username'; 
}
if(!empty($_POST['pwd'])){
   $password = $_POST['pwd'];
}else{
    $password = null;
    echo 'Please fill in the password';
}