Calculate fuel cost

http://percentagecalculator.epizy.com/

Hello I have created this calculate for fuel cost. I see that everything are working fine, but I see the work NAN, this word dissparead when I have the result. How can I do for delete de NAN.

Thank very much
Regards

This?

2 Likes

Yes

Center is deprecated, and is no longer recommended for use.

You are missing </p> a bunch of times.

An input element is not really meant to be placed inside a paragraph element.

And it’s working perfectly fine for me.

2 Likes

I have changed to the version in php 5.4 and is working fine. Thanks

Take note

4 Likes

When the page is first loaded without input, then the GET values of num1/num2/num3 will not have any values. Since you’re trying to read data that doesn’t exist, weird things may happen. This will result in an error and either the code crashing or the value being returned will be null.

Then, just below that, you’re dividing null by null, which doesn’t make sense because null isn’t a number. Maybe PHP will try to cast it to zero, but then you’re dividing by zero, which also isn’t possible.

So I’m actually shocked that the code runs on PHP 5.4 at all, because the code is doing things that should be impossible.

But PHP has become a lot more strict in the last decade or so because it’s often better to just crash rather than try and make it work in a way that likely was not intended.

What you need is to check the input values, and only run the calculations if all three numbers are filled with non-zero (and probably non-negative) numbers. And don’t expect PHP to just kinda figure it out and do something for you if you don’t validate the input.

6 Likes

That can be done with Vanilla JavaScript or jQuery much more easily.

3 Likes

Any question because I want to try your services before buy hosting. If I buy the hosting I can put my version in php or you will change the version for all websites?
Thanks

Premium hosting uses HardenedPHP, so you can safely run older versions of PHP (including 5.4). Note that is is only available on premium hosting, though.

6 Likes

“Safely” should be taken with a grain of salt. Software that requires (severely) outdated versions of PHP is usually severely outdated as well. Which often means they contain known but unresolved security problems because the software was abandoned by the author(s). HardenedPHP prevents security issues on the server, but doesn’t make your website imperious to hacking. Running up to date software is always the more secure option.

And if you’re writing new software now, you should absolutely make sure that it runs on the latest versions of PHP. If it doesn’t work, then it’s your code that’s wrong, and downgrading PHP to make it work is not the solution.

Even HardenedPHP won’t be available everywhere at all times. So writing new software for outdated platform is something that should be avoided at all costs.

6 Likes

Hello; in this mommet the calculator is working fine with the vesion 7.4.
Thanks very much
Regards

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.