I'm doing a register form and I'm trying to write a code that will show error if user does not fill all fields. It works okay but for some reason it works only if I enter email. If I leave all fields empty and click register, I don't get any error and with all fields empty my cursor goes to email field and gets activated (this field) when I click register button. Something is wrong with this email but I cannot find any problem, so what is wrong?
PHP source code:
if(empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['email']) || empty($_POST['password']))
{
$error="Fill all fields!";
}
HTML:
<form action="register.php" method="POST">
<input style="margin-top:10px" type="text" value="First Name" name="fname" onblur="if (this.value == '') {this.value = 'First Name';}" onfocus="if (this.value == 'First Name') {this.value = '';}" />
<input type="text" value="Last Name" name="lname" onblur="if (this.value == '') {this.value = 'Last Name';}" onfocus="if (this.value == 'Last Name') {this.value = '';}" />
<input type="email" value="Adres e-mail" name="email" onblur="if (this.value == '') {this.value = 'Adres e-mail';}" onfocus="if (this.value == 'Adres e-mail') {this.value = '';}" />
<p><input type="password" value="Password" name="password" onblur="if (this.value == '') {this.value = 'Password';}" onfocus="if (this.value == 'Password') {this.value = '';}" /></p>
<button type="submit" name="submit"> Register</button> </br>
</br>
</form>