Jump to content

Warning: Division by zero


jokerfool

Recommended Posts

<?php
session_start();
include "includes/db_connect.php";
include "includes/functions.php";
logincheck();
$username=$_SESSION['username'];

$fetch=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'"));


$currank=$fetch->rank;
$rankp = $fetch->rankpoints;


if ($currank == "Tramp"){
$max = '350';
$old="1";

}elseif ($currank == "Theif"){
$max = '750';
$old="350";

}elseif ($currank == "Hooligan"){
$max = '2320';
$old="750";

}elseif ($currank == "Criminal"){
$max = '4000';
$old="2320";

}elseif ($currank == "Gangster"){
$max = '6000';
$old="4000";

}elseif ($currank == "Boss"){
$max = '7200';
$old="6000";

}elseif ($currank == "Supreme Boss"){
$max = '11500';
$old="7200";

}
elseif ($currank == "Don"){
$max = '17200';
$old="11500";

}
elseif ($currank == "Legendary Don"){
$max = '150000';
$old="17200";

}
elseif ($currank == "Mod"){
$max = '17048';
$old="1";
}
elseif ($currank == "Admin"){
$max = '17048';
$old="1";
}
elseif ($currank == "Owner"){
$max = '17048';
$old="1";
}
$percent = round((($rankp-$old)/($max-$old))*100, 1);

$check = mysql_query("SELECT * FROM `inbox` WHERE `read`='0' AND `to`='$username'");
$inbox=mysql_num_rows($check);
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<title></title>
	<link href="includes/marquee.css" rel="stylesheet" type="text/css" />
	<script src="includes/marquee.js" type="text/javascript"></script>

</head>   
<body dir="ltr">
	<div id="marquee">
		<div><a href="inbox.php" target="middle">Rank: <?php echo "$fetch->rank"; ?> | Money: <?php echo "£".makecomma($fetch->money).""; ?> | Location: <?php echo "$fetch->location"; ?> | Health: <?php echo "$fetch->health"; ?>% | Points: <?php echo "$fetch->points"; ?> | Crew: <?php if ($fetch->crew == "0"){ echo "None"; }else{ echo "$fetch->crew"; } ?> | Bullets: <?php echo "".makecomma($fetch->bullets).""; ?> | Inbox: <?php if ($inbox > 0 ) { echo "$inbox New message(s)."; } else {echo "No new messages."; } ?></a></div>
	</div>

</body>
</html>

Do this:

 

if ($max-$old == 0) {
   die("Error these two equal 0 Max: " . $max . " Old: " . $old . " Equals: " . ($max - $old));
}else {
   $percent = round((($rankp-$old)/($max-$old))*100, 1);
}

 

And see what displays/report back. I bet that $max and $old are not hitting any of the if statements, thus they do not have a value which in return would give the division by zero error. If you can have a default value for $max and $old I would set that in your script before the if's or set it as an else at the end of the if's so this error does not happen if the $currank is not apart of any of the if's.

Archived

This topic is now archived and is closed to further replies.

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