if(!$_POST['username'] || ['password']) {
  	 die('Error: Username / Password field was blank');
	 }

What is the mistake in the code above. I want the syntax to check if either one of the fields are blank.

if(!$_POST['username'] || !$_POST['password']) {
  	 die('Error: Username / Password field was blank');
	 }

That doesn't check for blank. Try

if(empty($_POST['username'])){
   echo "Empty username!";
}
//or you can also do it this way
if($_POST['username']==""){
 echo "Empty username!";
}
if($_POST['username']==""){
	echo "Username field is EMPTY!";
}
elseif($_POST['password']==""){
	echo "Password field is EMPTY!";
}
else($_POST['username']=="") && ($_POST['password']=="") {
  	 echo "Username & Password field are EMPTY!";
}

Whats wrong with the whole code?

if($_POST['username']==""){
  echo "Username empty!";
} 
if($_POST['password']==""){
 echo "Password empty!";
}
if($_POST['username']=="" && $_POST['password']=="") {
 echo "Both username and password is empty!";
}

This will do the same as what you are trying to do.

if($_POST['username']==""){
  echo "Username empty!";
} 
if($_POST['password']==""){
 echo "Password empty!";
}
if($_POST['username']=="" && $_POST['password']=="") {
 echo "Both username and password is empty!";
}

The looping doesn't work.

if(empty($_POST['username'])) {
die('Username field was blank');
}
if(empty($_POST['password'])) {
die('Password field was blank');
}
if(empty($_POST['username']) && empty($_POST['password'])) {
die('Both field was blank');
}

This is working but if both the username and password was blank, it can't display the 3rd condition's result. Instead of that, it echo back the 1st condition's result.

if(empty($_POST['username']) && empty($_POST['password'])) {
	echo "Both empty"; 
	exit;
} 
if(empty($_POST['username'])){
	echo "username empty!";
	exit;
} 
if(empty($_POST['pass'])){
	echo "pass empty!";
	exit;
}

First validate for both the fields. Then other fields.

if(empty($_POST['username'])) {
die('Username field was blank');
}
if(empty($_POST['password'])) {
die('Password field was blank');
}
if(empty($_POST['username']) && empty($_POST['password'])) {
die('Both field was blank');
}

and if I arrange it like this,

if(empty($_POST['username']) && empty($_POST['password'])) {
die('Both field was blank');
}
if(empty($_POST['username'])) {
die('Username field was blank');
}
if(empty($_POST['password'])) {
die('Password field was blank');
}

It works!

can know how do I use css in php. I mean how do I use,

<div class = "error">
</div>

to style the echo msg .... e.g looping above

echo "<div class='error'>Text</div>"; If you want to use double quotes, you should escape those quotes. Eg. echo "<div class=\"error\">Text</div>";

if(empty($_POST['password'])) {
die('<div class="error">Password field was blank</div>');
}

When I used this code, it works, but the div tag gives a pinkish background whereas I've already set the background color in the css as black. Is the any other method using this css without a div tag.

manage to solve, my mistake. Anyway thanks for the support!

This question has already been answered. Start a new discussion instead.