Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['cm']))
  3. {
  4.    if(!is_numeric($_POST['cm']))
  5.    {
  6.       $error = 'Is not a number!';
  7.    }
  8.    else
  9.    {
  10.       $m = $_POST['cm'] / 100;
  11.    }
  12. }
  13. ?>
  14. <!doctype html>
  15. <html>
  16.    <head>
  17.       <title>Centimeters to meters converter</title>
  18.       <style type="text/css">
  19.       .error {
  20.       color: #f00;
  21.       }
  22.       </style>
  23.    </head>
  24.    
  25.    <body>
  26.       <form method="POST">
  27.          <label for="cm">Centimeters</label>
  28.          <input type="text" id="cm" name="cm" value="<?php if(isset($m)){echo $_POST['cm'];} ?>" size="5" />
  29.          <button type="submit">Convert</button>
  30.       </form>
  31. <?php
  32. if(isset($error))
  33. {
  34.    echo "      <span class=\"error\">{$error}</span>\n";
  35. }
  36. elseif(isset($m))
  37. {
  38.    echo "      There are <strong>{$m}</strong> meters to <strong>{$_POST['cm']}</strong> centimeters\n";
  39. }
  40. ?>
  41.    </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement