trying to create the front end to a script that will calculate the area and circumference of a circle.
(1)HTML form that will contain three input fields and a submit buttom
(2) will have only one text input field that input field is radius
(3)Create a calculation script with the following data:

Variables: Readius, Area, and Circumference
Constant: Pi = 3.1415926535

this is the script i have written so far

(HTML Form)
<html>
<head>
<title>
Calculation Form
</title>
</head>
<body>
<form method="post action="circumference.php">
<p>Radius:<input type="text" name="val1" size=10></p>
<p><input type="text" name="val2" size=10></p>
<p><input type="text" name="val3" size=10></p>
<p><input type="submit" name="submit" value="calculate"></p>
</form>

</body>
</html>


(PHP Calculation Script)
<?
if (($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[calc] =="")) {
    // more code goes here
}
header("Location: http://127.0.0.1/findcirc.html"); exit;

if ($_POST[calc]== "add") (
$result = $_POST[val1] + $_POST[val2];

) else if ($_POST[calc] == "variables") { 
    $result= $_POST[val1] - $_POST[val2];

} else if ($_POST[calc]) == "radius") {
    $result = $_POST[val1] * $_POST[val2];

} else if ($_POST[calc] == "cirumference") {
    $result = $_POST[val1] / $_POST[val2];
}
?>

Thnk

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Well I dont think you need php for that. It might be overkill. Use JavaScript. When you use php or any other server-side language, whenever your user wants to make a calculation, the page will have to contact the server, which means the page will refresh, which mean you will have to extra work to plug in the variables to the form so the user can see what they entered.

If you use JS, the page doesn’t refresh, you don’t have to plug the variables back into the form, and JS is perfectly capable of doing math that you want


-Brad

bwest, my guess--and of course I could be wrong--is that this is a school assignment. The nature of the task and the requirements seem to indicate as much. If this is the case, he/she may be required to use PHP. Also, if this is the case, the person should ask for help with a specific step, not expect us to provide a full working solution based on the initial requirements. Do you want to learn to fish or be given a fish?

I agree with you, though, I'd use client-side javascript to accomplish the stated goal.

This article has been dead for over six months. Start a new discussion instead.