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;

}

?>

Link to comment
Share on other sites

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 ===.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.