se7enet purgatorio

Page 1 of 1 1
Topic Options
Rate This Topic
#15214 - 07/23/07 06:24 AM Division By Zero.
HarleyJ
Malt-o-Meal


Registered: 07/23/07
Posts: 1

Offline
I noticed this error on my index.php page before you login.

 Quote:

Warning: Division by zero in /home/flashmor/public_html/valhallen/lib.php on line 208

Warning: Division by zero in /home/flashmor/public_html/valhallen/lib.php on line 210


The selected text for the Errors specified were:

 Quote:

$stathp = ceil($userrow["currenthp"] / $userrow["maxhp"] * 100);
if ($userrow["maxmp"] != 0) { $statmp = ceil($userrow["currentmp"] / $userrow["maxmp"] * 100); } else { $statmp = 0; }
$stattp = ceil($userrow["currenttp"] / $userrow["maxtp"] * 100);


I cannot see an error at all, If there is something that I cannot see, it would be greatfull for a fix as users using IE get the error:
 Quote:
page cannot be displayed, only top level element is allowed


Appreciated =)

Top
#15217 - 07/23/07 10:14 AM Re: Division By Zero. [Re: HarleyJ]
Fayt
Crunchberries
***

Registered: 11/08/05
Posts: 1131
Loc: My Computer, USA

Offline
It is causing a negitive number.
_________________________
MasterFayt - Amara 5 - Manas - Banar

Top
#15224 - 07/23/07 05:48 PM Re: Division By Zero. [Re: Fayt]
AnmanIndustries
Cookie Crisp
*****

Registered: 03/21/05
Posts: 2876
Loc: Planet Stupid, AKA Earth

Offline
You say this apears before you log in? Funny that, this is no part of the STOCK CODE anymore, as the lines you have shown us, do NOT apear before you log in.

Thread moved.

Here is your problem

Can someone please tell me what the problem with this is:

 Quote:

$stathp = ceil($userrow["currenthp"] / $userrow["maxhp"] * 100);
if ($userrow["maxmp"] != 0) { $statmp = ceil($userrow["currentmp"] / $userrow["maxmp"] * 100); } else { $statmp = 0; }
$stattp = ceil($userrow["currenttp"] / $userrow["maxtp"] * 100);


No need to, I already know the problem.
$userrow["currenthp"] $userrow["maxhp"]
$userrow["maxmp"] userrow["currenttp"] userrow["maxtp"] and whatever use has USER ROW in it.

Can any one tell me what the USERROW is? Thats right children. It is the array that stores all the LOGED IN users character info.

What happens, when you state a variable, that hasnt been said? Wow children, you sure KNOW HOW TO CODE PHP, because you are absolutly right. If you DONT set a variable, the variable is EMPTY. Or, in the case of a number check, it is 0.

So, if youre not logged in, and you have varialbes that are SUPPOSE to have numbers, and you try to devide a number by 0... this is the error you are getting.
_________________________
If you want me to punch you in the nuts go to:
http://www.AnmanIndustries.com

I'll do it for free too. Enjoy.

Top
#15227 - 07/23/07 08:05 PM Re: Division By Zero. [Re: AnmanIndustries]
Fayt
Crunchberries
***

Registered: 11/08/05
Posts: 1131
Loc: My Computer, USA

Offline
Yep makes sense to me.

I've had it by doing negitive too. But every code is different.


Edited by masterofollies (07/23/07 08:06 PM)
_________________________
MasterFayt - Amara 5 - Manas - Banar

Top
#15231 - 07/24/07 04:37 AM Re: Division By Zero. [Re: Fayt]
AnmanIndustries
Cookie Crisp
*****

Registered: 03/21/05
Posts: 2876
Loc: Planet Stupid, AKA Earth

Offline
negative numbers are dividable.
_________________________
If you want me to punch you in the nuts go to:
http://www.AnmanIndustries.com

I'll do it for free too. Enjoy.

Top
#15234 - 07/24/07 10:30 AM Re: Division By Zero. [Re: AnmanIndustries]
Fayt
Crunchberries
***

Registered: 11/08/05
Posts: 1131
Loc: My Computer, USA

Offline
Depends on how your coding it. -1 can be divided by 0 ?
_________________________
MasterFayt - Amara 5 - Manas - Banar

Top
#15235 - 07/24/07 07:53 PM Re: Division By Zero. [Re: Fayt]
AnmanIndustries
Cookie Crisp
*****

Registered: 03/21/05
Posts: 2876
Loc: Planet Stupid, AKA Earth

Offline
Nothing can be devided by 0. But -1 can be devided by -1 and so on. Basicly, we are both right. I was just more right than you. Like communism.

Any number, regardless if it is negative or not, can be devided with another number, that is not 0. end of story.
_________________________
If you want me to punch you in the nuts go to:
http://www.AnmanIndustries.com

I'll do it for free too. Enjoy.

Top
#15237 - 07/24/07 08:20 PM Re: Division By Zero. [Re: AnmanIndustries]
Fayt
Crunchberries
***

Registered: 11/08/05
Posts: 1131
Loc: My Computer, USA

Offline
Right by a negitive number cannot be divided by 0. End of story
_________________________
MasterFayt - Amara 5 - Manas - Banar

Top
#15527 - 08/30/07 10:32 AM Re: Division By Zero. [Re: Fayt]
CBeTHaX
Malt-o-Meal


Registered: 08/24/07
Posts: 8

Offline
All this can be accomplished by writing @ in front of a function. In this case it will be:

 PHP:
$stathp = @ceil($userrow["currenthp"] / $userrow["maxhp"] * 100); if ($userrow["maxmp"] != 0) { $statmp = @ceil($userrow["currentmp"] / $userrow["maxmp"] * 100); } else { $statmp = 0; } $stattp = @ceil($userrow["currenttp"] / $userrow["maxtp"] * 100);


The other way to not get an error is to write the following function on the top of index.php after <?php :
 PHP:
error_reporting(0);


Top
#15528 - 08/30/07 07:25 PM Re: Division By Zero. [Re: CBeTHaX]
Fayt
Crunchberries
***

Registered: 11/08/05
Posts: 1131
Loc: My Computer, USA

Offline
Why not use maxhp='.$userrow["currenthp"].',maxmp='.$userrow["currentmp"].',maxtp='.$userrow["currenttp"].'
You can do it that way too
_________________________
MasterFayt - Amara 5 - Manas - Banar

Top
Page 1 of 1 1


Hop to:

se7enet

Barack Obama Logo