Note that ===
is strict comparison. I think the following:
$num_rows === '0'
should rather be:
$num_rows == 0
$num_rows
is presumably an integer and not a string (a piece of text).
Related: PHP ==
vs ===
on Stack Overflow
Watch out with the second comparison, too:
$_GET['id'] !== $_SESSION['UserID']
Here, it's probably better to use !=
in favor of !==
as well. $_GET
is generally read as string, so even something like ?id=5
will return as string "5"
and not as integer 5
Here's a quick test to illustrate:
if (isset($_GET['id'])) {
echo '<h2>Comparison with == 5</h2>';
var_dump( ($_GET['id'] == 5) );
echo '<h2>Comparison with == "5"</h2>';
var_dump( ($_GET['id'] == "5") );
echo '<h2>Comparison with === 5</h2>';
var_dump( ($_GET['id'] === 5) );
echo '<h2>Comparison with === "5"</h2>';
var_dump( ($_GET['id'] === "5") );
}
else {
echo 'Please set an ?id to test';
}
This will output (notice the third item is false) the following with ?id=5
:
Comparison with == 5
boolean true
Comparison with == "5"
boolean true
Comparison with === 5
boolean false
Comparison with === "5"
boolean true