Advertisement
khalequzzaman17

Grade Calculation with PHP

Nov 3rd, 2022 (edited)
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.03 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="utf-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1">
  6.     <title>Grade Calc</title>
  7.     <link href='https://fonts.googleapis.com/css?family=ABeeZee' rel='stylesheet'>
  8.     <style>
  9.         * {
  10.             box-sizing: border-box;
  11.             font-family: ABeeZee;
  12.             text-align: center;
  13.         }
  14.         input[type=number], select, textarea {
  15.             width: 100%;
  16.             padding: 12px;
  17.             border: 1px solid #ccc;
  18.             border-radius: 4px;
  19.             resize: vertical;
  20.         }
  21.         label {
  22.             padding: 12px 12px 12px 0;
  23.             display: inline-block;
  24.         }
  25.         input[type=submit] {
  26.             background-color: #04AA6D;
  27.             color: white;
  28.             padding: 12px 20px;
  29.             border: none;
  30.             border-radius: 4px;
  31.             cursor: pointer;
  32.             float: right;
  33.         }
  34.         input[type=submit]:hover {
  35.             background-color: #45a049;
  36.         }
  37.         .h3 {
  38.             text-align: center;
  39.             font-size: 33px;
  40.         }
  41.         .container {
  42.             border-radius: 5px;
  43.             background-color: #f2f2f2;
  44.             padding: 20px;
  45.         }
  46.         .col-25 {
  47.             float: left;
  48.             width: 25%;
  49.             margin-top: 6px;
  50.         }
  51.         /* Clear floats after the columns */
  52.         .row:after {
  53.             content: "";
  54.             display: table;
  55.             clear: both;
  56.         }
  57.         /* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
  58.         @media screen and (max-width: 600px) {
  59.             .col-25, input[type=submit] {
  60.                 width: 100%;
  61.                 margin-top: 0;
  62.             }
  63.         }
  64.     </style>
  65. </head>
  66. <body>
  67. <?php
  68.  
  69. // Define Variables
  70. $bangla_1st = $bangla_2nd = $english_1st = $english_2nd = $general_math = $higher_math = $biology = $physics = $chemistry = $social_science = $religious = "";
  71.  
  72. // Request Method
  73. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  74.     $bangla_1st = getResult($_POST["bangla_1st"]);
  75.     $bangla_2nd = getResult($_POST["bangla_2nd"]);
  76.     $english_1st = getResult($_POST["english_1st"]);
  77.     $english_2nd = getResult($_POST["english_2nd"]);
  78.     $general_math = getResult($_POST["general_math"]);
  79.     $higher_math = getResult($_POST["higher_math"]);
  80.     $biology = getResult($_POST["biology"]);
  81.     $physics = getResult($_POST["physics"]);
  82.     $chemistry = getResult($_POST["chemistry"]);
  83.     $social_science = getResult($_POST["social_science"]);
  84.     $religious = getResult($_POST["religious"]);
  85. }
  86.  
  87. // Get Data/Results
  88. function getResult($data) {
  89.     $data = trim($data);
  90.     $data = stripslashes($data);
  91.     $data = htmlspecialchars($data);
  92.     return $data;
  93. }
  94.  
  95. // Grade Calculation
  96. function gradeCacl() {
  97.     if (0 >= 80 && 0 <= 100) {
  98.         echo "A+";
  99.     } elseif (0 >= 70 && 0 <= 79) {
  100.         echo "A";
  101.     } elseif (0 >= 60 && 0 <= 69) {
  102.         echo "A-";
  103.     } elseif (0 >= 50 && 0 <= 59) {
  104.         echo "B";
  105.     } elseif (0 >= 40 && 0 <= 49) {
  106.         echo "C";
  107.     } elseif (0 >= 33 && 0 <= 39) {
  108.         echo "D";
  109.     } elseif (0 >= 00 && 0 <= 32) {
  110.         echo "F";
  111.     }
  112. }
  113.  
  114. ?>
  115. <div class="h3">Grade Calc</div>
  116. <div class="container">
  117.     <form name="grade_calc" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  118.     <div class="row">
  119.         <div class="col-25">
  120.             <label>Bangla First Paper</label>
  121.             <label>
  122.                 <input type="number" name="bangla_1st" required />
  123.             </label>
  124.         </div>
  125.  
  126.         <div class="col-25">
  127.             <label>Bangla Second Paper</label>
  128.             <label>
  129.                 <input type="number" name="bangla_2nd" required />
  130.             </label>
  131.         </div>
  132.  
  133.         <div class="col-25">
  134.             <label>English First Paper</label>
  135.             <label>
  136.                 <input type="number" name="english_1st" required />
  137.             </label>
  138.         </div>
  139.  
  140.         <div class="col-25">
  141.             <label>English Second Paper</label>
  142.             <label>
  143.                 <input type="number" name="english_2nd" required />
  144.             </label>
  145.         </div>
  146.  
  147.         <div class="col-25">
  148.             <label>General Mathematics</label>
  149.             <label>
  150.                 <input type="number" name="general_math" required />
  151.             </label>
  152.         </div>
  153.  
  154.         <div class="col-25">
  155.             <label>Higher Mathematics</label>
  156.             <label>
  157.                 <input type="number" name="higher_math" required />
  158.             </label>
  159.         </div>
  160.  
  161.         <div class="col-25">
  162.             <label>Biology (G/Science)</label>
  163.             <label>
  164.                 <input type="number" name="biology" required />
  165.             </label>
  166.         </div>
  167.  
  168.         <div class="col-25">
  169.             <label>Physics (G/Science)</label>
  170.             <label>
  171.                 <input type="number" name="physics" required />
  172.             </label>
  173.         </div>
  174.  
  175.         <div class="col-25">
  176.             <label>Chemistry (Science)</label>
  177.             <label>
  178.                 <input type="number" name="chemistry" required />
  179.             </label>
  180.         </div>
  181.  
  182.         <div class="col-25">
  183.             <label>Social Science (H. C)</label>
  184.             <label>
  185.                 <input type="number" name="social_science" required />
  186.             </label>
  187.         </div>
  188.  
  189.         <div class="col-25">
  190.             <label>Islam/Hind (Religious)</label>
  191.             <label>
  192.                 <input type="number" name="religious" required />
  193.             </label>
  194.         </div>
  195.     </div>
  196.         <div class="row">
  197.             <input type="submit" value="Calculate Me!">
  198.         </div>
  199.     </form>
  200. </div>
  201.  
  202. <?php
  203.  
  204. if ($bangla_1st || $bangla_2nd || $english_1st || $english_2nd || $general_math || $higher_math || $biology || $physics || $chemistry || $social_science || $religious) {
  205.     echo "<p>Form Validation Results</p>";
  206.     if ($bangla_1st) {
  207.         echo "Bangla 1st Paper: " . $bangla_1st . "<br />";
  208.     }
  209.     if ($bangla_2nd) {
  210.         echo "Bangla 2nd Paper: " . $bangla_2nd . "<br />";
  211.     }
  212.     if ($english_1st) {
  213.         echo "English 1st Paper: " . $english_1st . "<br />";
  214.     }
  215.     if ($english_2nd) {
  216.         echo "English 2nd Paper: " . $english_2nd . "<br />";
  217.     }
  218.     if ($general_math) {
  219.         echo "General Math: " . $general_math . "<br />";
  220.     }
  221.     if ($higher_math) {
  222.         echo "Higher Math: " . $higher_math . "<br />";
  223.     }
  224.     if ($biology) {
  225.         echo "Biology: " . $biology . "<br />";
  226.     }
  227.     if ($physics) {
  228.         echo "Physics: " . $physics . "<br />";
  229.     }
  230.     if ($chemistry) {
  231.         echo "Chemistry: " . $chemistry . "<br />";
  232.     }
  233.     if ($social_science) {
  234.         echo "Social Science: " . $social_science . "<br />";
  235.     }
  236.     if ($religious) {
  237.         echo "Religious: " . $religious . "<br />";
  238.     }
  239. }
  240.  
  241. ?>
  242.  
  243. </body>
  244. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement