Our website was working perfectly fine for the last 6 months, and then just this month the page where we upload staff information has stopped working. We keep receiving a: Division by Zero error. Here is the area of the code that it says the error is in.....
if ($NewHeight=='1' and $NewWidth!='1') {
$NewHeight = ceil(($OldHeight*$NewWidth)/$OldWidth);
}
elseif ($NewWidth=='1' and $NewHeight!='1') {
$NewWidth = ceil(($OldWidth*$NewHeight)/$OldHeight);
}
elseif ($NewHeight=='1' and $NewWidth=='1') {
return(false);
}
Other way around mate; you can divide 0 by anything, but you cannot divide anything by 0.
So the problem will be with one of these:
$NewHeight = ceil(($OldHeight*$NewWidth)/$OldWidth);
$NewWidth = ceil(($OldWidth*$NewHeight)/$OldHeight);
$OldHeight_castr = ceil(($OldWidth*$NewHeight)/$NewWidth);
$OldWidth_castr = ceil(($OldHeight*$NewWidth)/$NewHeight);
$OldWidth, $OldHeight, $NewWidth, or $NewHeight will be 0. Start debugging or add print statements to see which one(s) is/are zero.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
It should be noted in PHP though that $x / 0 should actually work. Aside from triggering the error itself (which is just a warning mind you), it should return null if my assumption is correct. Attempting to use that in a numerical context will actually allow you to operate on it (or should if my initial assumptions are correct).
printf("\$z is: %d\n", $z); // $z is: 0
printf("++\$z is: %d\n", ++$z); // ++$z is: 1
Does that work out to one? Anyone that can test that? I assume that ++null = 1, though --null = well null. Hah.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Really? I'm a little suprised; the API states that null can be incremented to one (but not decremented, or I guess more accurately null is decremented to null). I'd have expected that ++$z would result in 1.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php