Jump to content

[SOLVED] can someone tell me why this conditional isn't working


cluelessnoob

Recommended Posts

It automatically goes to ulog.php no matter what I $email is

 

<?PHP

$email = trim($_POST['email']);

 

if ($email = "driver") {

include ('includes/ulog.php');

echo $email;

} elseif ($email = "manager") {

include ('includes/mlog.php');

echo $$email;

} else {

include ("includes/olog.php");

echo $email;

}

?>

as a side note:

 

= is a decleration. Declaring a variable with a value. (set)

== is conditional "Equal To", can take strings and compare with boolean values and integers etc.

 

=== is a "Is Exactly As", Explanation of "===";

 

$string = "True"; // This is a STRING, true.
$bool = true; // This is a native boolean value
$integer = 1; // This is a native numeric value
$nullval = null; // This is a declared NULL variable
$emptyval = ""; // This is not NULL, it is just empty

// consider the following statements:
if($string == true){
   // this works
}

if ($bool == true){
   // this works
   // ONLY this will work if every statement used '==='
}

if ($integer == true){
   // this works
}

if($nullval == false){
   // this works
}

if($emptyval == null){
   // this works
}

---

 

All of the above, although such different value types, will all execute.

If however you use the '===' operator instead of '==', you will be testing the "Type" of the value as well, so only the type match "bool $bool == bool true" will execute.

==

 

This can be useful to know and save you some headaches. == is much more leniant than ===.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.