Advertisement
HoneyRemedy

Untitled

Sep 16th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. <html>
  2.     <head>
  3.         <h1 style="font-size: 90;text-align: center;color:#b254b9"><i>A Normal Calculator</i><h1>
  4.     </head>
  5.     <body style="background-image:url('arry.jpg') ">
  6.         <form action ='' method="get">
  7.         <table style="background-color: #ffc433; margin: 0 450px; 0 0">
  8.  
  9.     <tr>
  10.         <td style="font-size: 19"><li style="color: white">Enter your number:</li></td>
  11.         <td><input type="number" name="number1" placeholder="Enter your number"></td>
  12.         <br/>
  13.     </tr>
  14.     <tr>
  15.         <td style="font-size: 19"><li style="color: white">Enter your number:</li></td>
  16.         <td><input type="number" name="number2" placeholder="Enter your numbers"></td>
  17.     </tr>
  18.  
  19.         </table>
  20.             <table style="background-color: #ea64e8; margin:0 660px; 0; 0">
  21.         <tr>
  22.             <td>
  23.             <select name="value">
  24.             <option value="sum">+</option>
  25.             <option value="sub">-</option>
  26.             <option value="mul">*</option>
  27.             <option value="div">/</option>
  28.             </select>
  29.             </td>
  30.             <td>
  31.                 <input type="submit" name='submit' value="calculation">
  32.             </td>
  33.         </tr>
  34.             </table>
  35.             <div style="margin:0 635px; 0 0">
  36.                 <input type="text" value="<?php echo cal(); ?>" placeholder="result">
  37.             </div>
  38.         </form>
  39.     </body>
  40. </htmal>
  41.  
  42. <!--########## PHP Starts ###########-->
  43. <?php
  44.    
  45.     function cal()
  46.     {
  47.  
  48.         if (isset($_GET['submit']))
  49.         {
  50.    
  51.             $bd= array
  52.                     (
  53.                         $_GET['number1'],
  54.                         $_GET['number2'],
  55.                         $_GET['value'],
  56.                         $result= ''
  57.                     );
  58.  
  59.             switch($bd[2])
  60.             {
  61.                 case 'sum': $bd[3]=$bd[0]+$bd[1];   break;
  62.                 case 'sub': $bd[3]=$bd[0]-$bd[1];   break;
  63.                 case 'mul': $bd[3]=$bd[0]*$bd[1];   break;
  64.                 case 'div': $bd[3]=$bd[0]/$bd[1];   break;
  65.             }
  66.  
  67.             //if($bd[3]=='')
  68.             //{
  69.             //  $bd[3] = "please enter data";
  70.             //}
  71.             //  else
  72.             //  $bd[3] = $bd[3];               
  73.             //
  74.             //echo $bd[3];
  75.  
  76.             echo $bd[3] = empty($bd[3]) ? "please enter data": $bd[3] ;
  77.         }
  78.         else
  79.         return "please calculation";
  80.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement