Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 1);
- $result = '';
- if(isset($_POST['calculate'])) {
- if(empty($_POST['firstValue']) && empty($_POST['lastValue'])) { // here $_POST
- echo "<script>alert('Please enter values')</script>";
- }
- elseif (empty($_POST['firstValue'])) {// here $_POST
- echo "<script>alert('Please enter first value')</script>";
- }
- elseif (empty($_POST['lastValue'])) {// here $_POST
- echo "<script>alert('Please enter second value')</script>";
- }
- elseif (filter_var($_POST['firstValue'], FILTER_VALIDATE_INT) === false) {// here $_POST
- echo "<script>alert('First value must be numeric')</script>";
- }
- elseif (filter_var($_POST['lastValue'], FILTER_VALIDATE_INT) === false) {// here $_POST
- echo "<script>alert('Last value must be numeric')</script>";
- }
- else {
- $operator = $_POST['operator'];
- switch ($operator) {
- case '+':
- $add1 = $_POST['firstValue'];
- $add2 = $_POST['lastValue'];
- $result = $add1 + $add2;
- break; // here
- case '-':
- $add1 = $_POST['firstValue'];
- $add2 = $_POST['lastValue'];
- $result = $add1 - $add2;
- break; // here
- case '*':
- $add1 = $_POST['firstValue'];
- $add2 = $_POST['lastValue'];
- $result = $add1 * $add2;
- break; // here
- case '/':
- $add1 = $_POST['firstValue'];
- $add2 = $_POST['lastValue'];
- $result = $add1 / $add2;
- break;
- default:
- $result = '';
- echo "not accepted";
- break;
- }
- }
- }
- ?>
- <form action="" method="POST"> <!-- here method="POST" -->
- <table style="border: groove #00FF99">
- <tr>
- <td style="background-color: aqua; color: red; font-family: Arial;">Enter first number</td>
- <td colspan="1"><input type="text" name="firstValue" style="color: red;"></td>
- <tr>
- <td style="color:burlywood; font-family: Arial;">Select Operator</td>
- <td>
- <select name="operator" style="width: 63px;">
- <option>+</option>
- <option>-</option>
- <option>*</option>
- <option>/</option>
- </select>
- </td>
- </tr>
- <tr>
- <td style="background-color: aqua; color: red; font-family: Arial;">Enter second number</td>
- <td class="auto-style5"><input type="text" name="lastValue" style="color: red;"></td>
- </tr>
- <tr>
- <td></td>
- <td><input type="submit" name="calculate" value="Calculate" style="color: wheat; background-color: rosybrown;"> </td>
- </tr>
- <tr>
- <td style="background-color: aqua; color: red;">Output =</td>
- <td style="color: darkblue;"><?php echo $result; ?></td>
- </tr>
- </tr>
- </table>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement