Lucas Ting Lucas Ting - 5 months ago 9
PHP Question

Displaying object's data

How can I make the

$validation
false, I tried this but it will never return false to me.

if (isset($_POST['submit'])) {
// starting date post data
$startDay = $_POST['startDay'];
$startMonth = $_POST['startMonth'];
$startYear = $_POST['startYear'];

// ending date post data
$endDay = $_POST['endDay'];
$endMonth = $_POST['endMonth'];
$endYear = $_POST['endYear'];

// team post data
$team = $_POST['selectTeam'];
$validation = true;

if ($validation) {
if (!isset($startDay) || $startDay === 'defaultDay') {
$validation = false;
}

if (!isset($startMonth) || $startMonth === 'defaultMonth') {
$validation = false;
}

if (!isset($startYear) || $startYear === 'defaultYear') {
$validation = false;
}

if (!isset($endDay) || $endDay === 'defaultDay') {
$validation = false;
}

if (!isset($endMonth) || $endMonth === 'defaultMonth') {
$validation = false;
}

if (!isset($endYear) || $endYear === 'defaultYear') {
$validation = false;
}

if (!isset($team) || $team === 'defaultTeam') {
$validation = false;
}

if ($validation=true) {
echo 'testing';
} elseif ($validation=false) {
echo 'false';
}
}
}

Answer

Issue is

if ($validation = true) {
    echo 'testing';
} else if ($validation = false) {
    echo 'false';
}

change it to

if ($validation === true) {
    echo 'testing';
} else{
    echo 'false';
}
Comments