I’m trying to do some very basic arithmetic and am getting hung up. I’m pulling variables from a URL like this:
http://mysite.com/page.php?var1=100&var=5
This is the basic /page.php code I’m using:
<?php
$var1 = "var1";
$var2 = "var2";
$divided_amount = $var1/$var1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Derp</title>
</head>
<body style="background-color: #fff; text-align: center;">
<div style="text-align: center; width: 1000px; background-color: #fff; margin: auto;">
<p>This should be the divided amount: <?php echo $divided_amount ?> </p>
</body>
</html>
However, I end up getting this error message:
Warning: Division by zero in /derp.php on line 4
Is this even possible to do with passed variables? If so, where am I going wrong? Any help is greatly appreciated!
You are dividing a string by another string. Try replacing your PHP code with this: