Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['calc']))
- {
- $calc = $_POST['calc'];
- }
- else
- {
- $calc = "";
- }
- if(isset($_POST['val1'], $_POST['val2']))
- {
- if ($_POST['val1'] == "" || $_POST['val2'] == "")
- {
- header("Location: ./temp.php");
- exit;
- }
- else
- {
- $val1 = $_POST['val1'];
- $val2 = $_POST['val2'];
- }
- }
- switch ($calc)
- {
- case "add":
- $result = $val1 + $val2;
- break;
- case "subtract":
- $result = $val1 - $val2;
- break;
- case "multiply":
- $result = $val1 * $val2;
- break;
- case "divide":
- $result = $val1 / $val2;
- break;
- }
- if(!isset($result))
- {
- echo "<p>Please fillout all the forums.</p>";
- }
- else
- {
- echo "<title>Calculation Result</title>";
- echo "<p>The result of the calculation is: $result</p>";
- echo "<p><a href=\"temp.php\" target=\"_self\">Do Another</a></p>";
- }
- ?>
- <html>
- <head>
- <title>Calculator</title>
- </head>
- <body>
- <form method="post" action="temp.php">
- <p>Value 1: <input type="text" name="val1" size="10"></p>
- <p>Value 2: <input type="text" name="val2" size="10"></p>
- <p>Calculation:<br>
- <input type="radio" name="calc" value="add"> add<br>
- <input type="radio" name="calc" value="subtract"> subtract<br>
- <input type="radio" name="calc" value="multiply"> multiply<br>
- <input type="radio" name="calc" value="divide"> divide</p>
- <p><input type="submit" name="submit" value="Calculate"></p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement