Advertisement
michaelyuen

Untitled

Dec 20th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.     $value1 = $value2 = $error1 = $error2 = '';
  4.  
  5.     if (isset($_POST['submit'])) {
  6.             $value1 = $_POST['post1'];
  7.             $value2 = $_POST['post2'];
  8.             if (strlen($value1) < 8) {
  9.                 $error1 = 'minimum 8 characters';
  10.             }
  11.             if (!is_numeric($value2)) {
  12.                 $error2 = 'must be numeric';
  13.             }
  14.             if (empty($value1)) {
  15.                 $error1 = 'this field is required';
  16.             }
  17.             if (empty($value2)) {
  18.                 $error2 = 'this field is required';
  19.             }
  20.             if (empty($error1) && empty($error2)) {
  21.                 // insert your data;
  22.                 header('location: '. $_SERVER['PHP_SELF']);
  23.             }
  24.     }
  25. ?>
  26. <DOCTYPE html>
  27. <html>
  28. <head><head>
  29. <body>
  30.     <form action="" method="POST">
  31.         <input type="text" name="post1" value="<?= $value1; ?>" placeHolder="Minumum 8 Characters">
  32.         <div class="error"><?= $error1; ?></div>
  33.         <input type="text" name="post2" value="<?= $value2; ?>" placeHolder="Must Be Numeric Value">
  34.         <div class="error"><?= $error2; ?></div>
  35.         <input type="submit" name="submit" value="submit">
  36.     </form>
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement