Advertisement
Guest User

Till Sakke

a guest
Feb 2nd, 2019
125
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.  
  3. /*
  4.  
  5. 1. User clicks HTML-form submit button
  6.  
  7. 1.1. Error handler 1 - Checks for empty fields and cancels submission if empty fields are detected.
  8.  
  9. 2. Switch statement to give suiting error messages based on results from error handlers.
  10.  
  11. */
  12.  
  13. if (isset($_POST['submitButton'])) {
  14.  
  15.     // Requires dbh-file for connection to MySQLi-database
  16.  
  17.     require 'dbh.inc.php';
  18.  
  19.     // PHP-variables for input fields (3)
  20.  
  21.     $username = $_POST['username'];
  22.     $password = $_POST['password'];
  23.     $rePassword = $_POST['rePassword'];
  24.  
  25.     // Error handler 1
  26.  
  27.     if (empty($username) || empty($password) || empty($rePassword)) {
  28.         header('Location: signup.php?error=empty_inputs');
  29.         die();
  30.     }
  31.  
  32.     // Switch statement for generating error messages
  33.  
  34.     if (isset($_GET['error'])) {
  35.  
  36.         switch($_GET['error']) {
  37.  
  38.             case 'empty_inputs':
  39.             echo 'Please fill in all fields to proceed.';
  40.             break;
  41.  
  42.             default:
  43.             echo 'Unknown error.';
  44.             break;
  45.  
  46.         }
  47.  
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement