Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 11 months ago.
Improve this question
I´m trying to use or operator in a php sentence but only validate the first condition, what´s wrong?
if ($_SESSION['user_id'] != 4 || $_SESSION['rol'] != 1)
{
//exit
}else{
//do something
}```
You should invert the condition in this way:
if ($_SESSION['user_id'] == 4 || $_SESSION['rol'] == 1)
//it's ok
else
//exit
Because otherwise if the user_id is 4 it will otherwise fail if it doesn't have the role expected
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
What could be the cause of this error? I already check it with if/else statement in the first level. How can it still show the "Division by zero" error?
if($sum != 0) {
$percent = (($sum / $tss) * 100);
} else {
$percent = 0;
}
You check $sum. You should be checking $tss.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm trying to fail on purpose... According to the documentation get_term_by will return false when nothing is found.
I issue:
$exiting_term = get_term_by('slug', sanitize_title("something"), 'non-existing-one');
Then I...
var_dump($existing_term);
The output from which is:
bool(false)
However, my code will not to into this block. Why is that?
if ($existing_term === false) {
/// NEVER GETS HERE.
}
You have a typo.
var_dump('exiting_term' == 'existing_term');
--> bool(false)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I have a mysql field called "time_of_birth" that is definitely set to NULL.
I have a PHP check on that field like this:
if ($row['time_of_birth'] !== "00:00:00") {
//do this stuff
} else {
//do something else
}
For that field that is definitely set to NULL, it's doing the "do this stuff". Isn't NULL different than "00:00:00"? I would expect it to do "do something else" because it's not exactly equal to "00:00:00".
What am I missing here?
I think it is doing it correctly. It is not seeing null as equal to '00:00:00' !== is a proof that it is not seeing it as same and entering that block.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm not the best at php and mysql and i'm still learning however i have this userlevel variable which i define in my session
and if i message it back to myself using
<?php echo"$session->userlevel"; ?>
It'll work, it'll tell me that me that my userlevel is "0" which it should be however when i'm using an if statement to check it won't work?
<?php
if ($_SESSION['userlevel'] = 0) {
echo "Userlevel 0 was found!";
}
?>
Any though
if($_SESSION['userlevel'] = 0)
should be
if($_SESSION['userlevel'] == 0)
Otherwise you don't check, you assign the value 0 to $_SESSION['userlevel']
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to have 3 actions based on an order being 0 percent fulfilled, 100 percent fulfilled or somewhere in the middle.
The tests I have ran so far suggest this is correct but as I could check every possibility I was hoping someone could run their eyes over it and point out any obvious wrong-doings.
//$success & $unsuccess are counts of the good/bad fulfilment items.
$percentfulfilled = round((($success/($success+$unsuccess))*100),2);
//If 0% fulfillled
if($percentfulfilled == '0')
{
}
//If 1-99% fulfilled
elseif($percentfulfilled < '100' && $percentfulfilled > '0')
{
}
//If 100% fulfilled
elseif($percentfulfilled = 100)
{
}
Your last statement is missing an equal
elseif($percentfulfilled == 100)
//^here
In the last stament you were not checking the condition but you were assigning a value to variable.