So i'm a beginner and trying to figure out something that seems like it should be really easy:
I want someone to enter an amount in a text field, an amount in another text, multiply those numbers and multiply that by .2 and then post the result into another text field.
Months (text field)
Rent (text field)
Calculate (button)
Total (text field to display result of months*rent*.2)
Here is basic page:
<html>
<head>
</head>
<body>
<form method="post" action="handler.php">
<p>Months <input name="months" type="text" id="months"></p>
<p>Rent <input name="rent" type="text" id="rent"></p>
<p><input type="submit" name="Submit" value="Calculate"></p>
<p>Total<input name="total" type="text" id="total"></p>
</form>
</body>
</html>
This is what i would assume would handle this (handler.php):
<html>
<head>
</head>
<body>
<?php
$answer = $months * $rent * .2;
echo "$answer"; ?>
</body>
</html>
I'm sure this can be really simple but my knowledge is pretty limited.
Any help? also this (if it was right) would print it on a separate page rather than displaying it in the text field (Total)
Simple Calculator
Moderator: General Moderators
Re: Simple Calculator
Where are $months and $rent coming from? PHP doesn't define those automatically: how should it know what values they should get?
Take a look at how to handle form input.
Take a look at how to handle form input.
Code: Select all
<html>
<head>
</head>
<body>
<?php
$answer = $_POST["months"] * $_POST["rent"] * .2;
echo $answer; ?>
</body>
</html>