"Division by zero" PHP [closed] - php

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.

Related

Php Or operator doesn´works propertly [closed]

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

Why can't I identify the false? [closed]

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)

Checking userlevel but it won't work [closed]

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']

using variable in $_POST[] [closed]

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 suppose that this is very noob question but I can't figure it out.
I've got code:
for($i=1; $i<9; $i++){
if (isset($_POST['is'$i'ID'])) {
echo $i . " is OK<br>";
}
}
And I know that the problem lies in this line :
if (isset($_POST['is'$i'ID']))
How can I use variable i in this code?
String concatenation rules apply even when used as array keys:
if (isset($_POST['is'.$i.'ID']))
Simply concat your strings. You even do it in your echo call :)
if (isset($_POST['is' . $i . 'ID']))

PHP Else, Elseif Logic Correct? [closed]

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.

Categories