PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm trying to make a calculator for a specific purpose, and so far I can't find any examples I can modify to work the way I want it to. Hopefully someone here can figure out what's wrong with it.
<html>
<head>
<title>Calculator</title>
</head>
<body>
<form name="e;calc"e; method=POST action="e;calc.php"e;>
Number of Ships:
<input name="e;ships"e; type="e;text"e; maxlength="e;3"e;><p>
Number of Weapons Fired:
<input name="e;fired"e; type="e;text"e; maxlength="e;3"e;><p>
Type of Weapon:
<select name="e;weapon"e;>
<option value="e;25"e;>Laser</option>
<option value="e;15"e;>Nuclear Missile</option>
*There's a bunch of values in here that I edited out for length*
<option value="e;100"e;>Homing Black Hole</option>
<option value="e;100"e;>Distortion Blaster</option>
</select>
<input type="e;submit"e; name="e;Submit"e; value="e;Submit"e;>
</form>
</body>
</html>
Secondly, in the code, always use $varname for variables. In the PHP code it seriously looks like you're resetting all the input, which makes no sense whatsoever.
<?php
// first load the POST input into regular variables
$ships = $_POST['ships'];
$fired = $_POST['fired'];
$weapon = $_POST['weapon'];
// check that $ships and $fired are under 1000, and that the weapon is 15/25/100
if (
($ships > 999)
or
($fired > 999)
or
( ($weapon != 15) and ($weapon != 25) and ($weapon != 100) )
)
{
print "Invalid input.";
}
// Equate $fired multiplied by $weapon divided by $ships into a var
else
{
$result = ( ($fired * $weapon) / $ships );
print $result;
}
?>
</body>
</html>