<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<title>PHP Example</title>
</head>
<body>

<?php
if ( isset($_POST['submit']) ) {
    # if the variable above exists then it means
    # that the form was already submitted

    # extract the posted (submitted) variables
    # your name           form name
    $val1=$_POST['val1'];
    $val2=$_POST['val2'];
    $calc=$_POST['calc'];

    # alternatively you can set the PHP driective:
    # register_globals = on
    # and use the listed variables directly (w/out name change)
    
    # handle the results
    if ($calc == "add") {$r = $val1 + $val2;}
    else if ($calc == "sub") {$r= $val1-$val2;}
    else if ($calc == "mul") {$r = $val1*$val2;}
    else if ($calc == "div") {$r = $val1/$val2;}
    echo "The result of the calculation is: $r <br />";
    echo "Try <a href=\"", $_SERVER['REQUEST_URI'], "\">again</a>?";

} else {
    # if the variable in if does not exist then it means
    # that the form was not submitted yet - we should print it
?>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    Value 1: <input type="text" name="val1" /><br />
    Value 2: <input type="text" name="val2" /><br />
    <input type="radio" name="calc" value="add" /> add<br />
    <input type="radio" name="calc" value="sub" /> subtract<br />
    <input type="radio" name="calc" value="mul" /> multiply<br />
    <input type="radio" name="calc" value="div" /> divide</br>
    <input type="submit" name="submit" value="Calculate" />
    </form>

<?php
}
?>

</body>
</html>