I want to write a PHP page that takes 3 numbers (starting,ending, incrementing) inputted by the user and increments it accordantly. If the starting number is smaller than the ending number increment as addition. If starting number is larger than ending number increment in subtraction. If both of those conditions are false, send an error to the web browser.
Now the user can input in increment field +number or -number.(ex: starting # 50 ending number # 10 Increment # -5)
I have a problem with that when the user adds a -/+ in front of the increment # I get stuck in a endless loop and even though the -Increment should subtract it is actually adding.
I have included my loop with this post. I hope someone can point me into the right direction.
<?php
$NumberI = $_POST["NumberI"];
$NumberII = $_POST["NumberII"];
$NumberInc= $_POST["NumberInc"];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Lab005 Html Page</title>
</head>
<body>
<?php
// Functions
echo "<p> The Starting Numbers you entered is: $NumberI</p>\n";
echo "<p> The Ending Numbers you entered is: $NumberII</p>\n";
echo "<p> The Increment Numbers you entered is: $NumberInc</p>\n";
while ($NumberInc > 0 ){
if ($NumberI < $NumberII){
while ($NumberI < $NumberII)
$NumberI = $NumberI + $NumberInc;
echo "<p>$NumberI</p>";
}
}
else if (!$NumberI < $NumberII){
echo "<p> incorrect input </p>";
}
}
while ($NumberInc <0){
if ($NumberI > $NumberII){
while ($NumberI > $NumberII){
$NumberI = $NumberI - $NumberInc;
echo "<p>$NumberI</p>";
}
}
else if ($NumberI < $NumberII){
echo "<p> Incorrect Input </p>";
}
}
?>
</body>
</html>

New Topic/Question
Reply



MultiQuote




|