A_God

PHP calculator

Nov 6th, 2021 (edited)
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.17 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Document
  8.     </title>
  9.     <title>Simple Calculator Program in PHP - Tutorials Class
  10.     </title>
  11.   </head>
  12.   <div class="bg">
  13.   </div>
  14.   <div id="calc-cart" class="bg bg2">    
  15.   </div>
  16.   <div id= "layer 3"class="bg bg3">  
  17.   </div>
  18.   <style>
  19.     h2 {
  20.       color: #970000;
  21.       font-family:Arial!important;
  22.     }
  23.     b {
  24.       font-family: arial;
  25.     }
  26.     #calc-cart {
  27.       background-color: bisque;
  28.       display: grid;
  29.     }
  30.     .inputs {
  31.       box-shadow:inset 0px -6px 20px 1px #a4e271;
  32.       background:linear-gradient(to bottom, #89c403 5%, #77a809 100%);
  33.       background-color:#89c403;
  34.       border-radius:33px;
  35.       display:inline-block;
  36.       cursor:pointer;
  37.       color:#ffffff;
  38.       font-family:Arial!important;
  39.       font-size:21px;
  40.       font-weight:bold;
  41.       font-style:italic;
  42.       padding:11px 24px;
  43.       text-decoration:none;
  44.       text-shadow:0px 3px 0px #528009;
  45.     }
  46.     .inputs:hover {
  47.       background:linear-gradient(to bottom, #77a809 5%, #89c403 100%);
  48.       background-color:#77a809;
  49.     }
  50.     .inputs:active {
  51.       position:relative;
  52.       top:1px;
  53.     }
  54.     html {
  55.       height:100%;
  56.     }
  57.     body {
  58.       margin:0;
  59.     }
  60.     .bg {
  61.       animation: slide 3s cubic-bezier(.99,.05,.12,1.02) infinite alternate;
  62.       background-image: linear-gradient(-45deg, #cca633 50%, #ac5845 50%);
  63.       bottom:0;
  64.       left:-50%;
  65.       opacity:.5;
  66.       position:fixed;
  67.       right:-50%;
  68.       top:0;
  69.       z-index:-1;
  70.     }
  71.     .bg2 {
  72.       animation-direction:alternate-reverse;
  73.       animation-duration:4s;
  74.     }
  75.     .bg3 {
  76.       animation-duration:5s;
  77.     }
  78.     .content {
  79.       background-color:rgba(255,255,255,.8);
  80.       border-radius: 18%;
  81.       box-shadow: rgba(255, 255, 255, 0.1) 0px 1px 1px 0px inset, rgba(50, 50, 93, 0.25) 0px 50px 100px -20px, rgba(0, 0, 0, 0.3) 0px 30px 60px -30px;
  82.       box-sizing:border-box;
  83.       left:50%;
  84.       padding:10vmin;
  85.       position:fixed;
  86.       text-align:center;
  87.       top:50%;
  88.       transform:translate(-50%, -50%);
  89.     }
  90.     h3 {
  91.       font-family:Arial, Helvetica, sans-serif;
  92.     }
  93.     @keyframes slide {
  94.       0% {
  95.         transform:translateX(-25%);
  96.       }
  97.       100% {
  98.         transform:translateX(25%);
  99.       }
  100.     }
  101.  
  102.  
  103. /* Inline #1 | https://localhost//phpstuff/calci2.php */
  104.  
  105.  
  106.  
  107. </style>
  108. <?php
  109. $first_number = $_POST['first_number'];
  110. $second_number = $_POST['second_number'];
  111. $operator = $_POST['operator'];
  112. $result = '';
  113. if (is_numeric($first_number) && is_numeric($second_number)) {
  114.     switch ($operator) {
  115.         case "Add":
  116.            $result = $first_number + $second_number;
  117.             break;
  118.         case "Subtract":
  119.            $result = $first_number - $second_number;
  120.             break;
  121.         case "Multiply":
  122.             $result = $first_number * $second_number;
  123.             break;
  124.         case "Divide":
  125.             $result = $first_number / $second_number;
  126.     }
  127. }
  128.  
  129. ?>
  130.  
  131. <body>
  132. <div class="content">
  133.  
  134.     <h2 style = "font-size:30px;">PHP - Simple Calculator Program</h2>
  135.       <form action="" method="post" id="calc-form">
  136.             <p>
  137.                 <input type="number" name="first_number" id="first_number" required="required" value="<?php echo $first_number; ?>" /> <b>First Number</b>
  138.             </p>
  139.             <p>
  140.                 <input type="number" name="second_number" id="second_number" required="required" value="<?php echo $second_number; ?>" /> <b>Second Number</b>
  141.             </p>
  142.             <p>
  143.                 <input readonly="readonly" name="result" value="<?php echo $result; ?>"> <b>Result</b>
  144.             </p>
  145.             <input type="submit" name="operator" value="Add" class="inputs" />
  146.             <input type="submit" name="operator" value="Subtract" class="inputs"/>
  147.             <input type="submit" name="operator" value="Multiply" class="inputs"/>
  148.             <input type="submit" name="operator" value="Divide" class="inputs"/>
  149.       </form>
  150.     </div>
  151.  
  152. </body>
  153. </html>
  154.  
Add Comment
Please, Sign In to add comment