What I want is to show the error (message), only if the user do a false action. For example, if the field is empty, it will show (Please fill all the fields). I've already done that, but the problem that I have is that it shows also if the user enter to the page for the first time, meaning it does NOT respects the (if condition) that I have written !
The question :
How to show the message only if one of the fields is empty ?
Any ideas on how I can solve it ?
Here is my code :
<? $conn = mysqli_connect('localhost', 'db', 'db_pass', 'db_name') or die("Error " . mysqli_error($conn)); $email = filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL); $old_password = trim($_POST['old_pass']); $new_password = trim($_POST['new_pass']); $email = mysqli_real_escape_string($conn,$email); $old_password = mysqli_real_escape_string($conn,$old_password); $new_password = mysqli_real_escape_string($conn,$new_password); if(empty($email) || empty($old_password) || empty($new_password)){ echo 'Please fill all the fields !<br>'; } else{ $sql="UPDATE users SET pass='$new_password' WHERE email='$email' AND pass='$old_password'" or die("Error " . mysqli_error($conn)); $result = mysqli_query($conn,$sql); mysqli_close($conn); } if($result){ echo'Password changed successfully !'; } elseif(!$result) { echo 'The email/password you provided is false !'; } ?>