I'm new to PHP. I'm trying to check that no field is empty in a certain form, so I used a foreach
statement but it only checks one by one instead of all at once.
Here is my code:
<?php
if (isset($_POST[submit])) {
ValidateUser();
}
function ValidateUser() {
$username = $_POST['username'];
$password = $_POST['password'];
$details = array($username, $password);
foreach($details as $detail) {
if (!empty($detail)) {
echo "hurrayy";
}
}
}
?>
So instead of displaying "hurrayy" when BOTH username and password are not empty, it displays as long as one of them is not empty. Please help.