Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_POST["calc"])){ // natisnat li e submit
- // read values from inputs
- $fn = $_POST["num1"];
- $sn = $_POST["num2"];
- $op = $_POST["operation"];
- if (is_numeric($fn) && is_numeric($sn)){
- switch ($op)
- {
- case "+": $result = $fn + $sn; break;
- case "-": $result = $fn - $sn; break;
- case "*": $result = $fn * $sn; break;
- case "/":
- if ($sn == 0){
- $result = "Второто ти число е 0!";
- } else {
- $result = $fn / $sn;
- }
- break;
- }
- } else {
- $result = "Не си въвел числа!";
- }
- }
- ?>
- <!DOCTYPE>
- <html>
- <head>
- <title>Моят калкулатор</title>
- </head>
- <body bgcolor="#f1f0ab">
- <form method="post" action="#">
- <table border="1" align="center">
- <tr>
- <td colspan="2" align="center">
- <h3>КАЛКУЛАТОР - PHP</h3>
- </td>
- </tr>
- <tr>
- <td>Въведи първото число:</td>
- <td> <input type="text" name="num1"> </td>
- </tr>
- <tr>
- <td>Въведи второто число:</td>
- <td> <input type="text" name="num2"> </td>
- </tr>
- <tr>
- <td><b>Избери операция:</b></td>
- <td align="center">
- <select name="operation">
- <option value="+">+</option>
- <option value="-">-</option>
- <option value="*">*</option>
- <option value="/">/</option>
- </select>
- </td>
- </tr>
- <tr>
- <td colspan="2" align="center">
- <input type="submit" name="calc" value="ПРЕСМЕТНИ">
- </td>
- </tr>
- <tr>
- <td>Резултат:</td>
- <td>
- <?php
- if (isset($result)){
- echo $result;
- }
- ?>
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement