Advertisement
michaelyuen

Untitled

Dec 2nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.21 KB | None | 0 0
  1. <?php
  2. ini_set('display_error', 1); // error display should come first
  3. error_reporting(E_ALL); // error display should come first
  4. require_once("database.php");
  5.  
  6. //define variables and initialize with empty values
  7.  
  8.     $firstnameError = $lastnameError = $emailError = $confirmemailError = "";
  9.     $firstname = $lastname = $email = $confirmemail = '';
  10.  
  11. if (isset($_POST['register'])) { // $_POST['register'] instead
  12.  
  13.  
  14.     if (empty($_POST['firstname'])) {
  15.         $firstnameError = "field required";
  16.     } else {
  17.         $firstname = $_POST['firstname'];
  18.     }
  19.  
  20.     if (empty($_POST['lastname'])) {
  21.         $lastnameError = "field required";
  22.     } else {
  23.         $lastname = $_POST['lastname'];
  24.     }
  25.  
  26.     if (empty($_POST['email'])) {
  27.         $emailError = "field required";
  28.     } else {
  29.         $email = $_POST['email'];
  30.     }
  31.  
  32.     if (empty($_POST['confirmemail'])) {
  33.         $confirmemailError = "field required";
  34.     } else {
  35.         $confirmemail = $_POST['confirmemail'];
  36.     }
  37. }
  38. ?>
  39.  
  40. <form method="POST" action="">
  41.     <div class="form-group">
  42.         <label>First Name</label>
  43.      <input type="text" class="form-control" placeholder="Enter first name" name="firstname" value="<?php echo htmlspecialchars($firstname);?>">
  44.      <span class="error"><?php echo $firstnameError;?></span>
  45.     </div>
  46.     <div class="form-group">
  47.         <label>Last Name</label>
  48.         <input type="text" class="form-control" placeholder="enter last name" name="lastname" value="<?php echo htmlspecialchars($lastname);?>">
  49.         <span class="error"><?php echo $lastnameError;?></span>
  50.     </div>
  51.     <div class="form-group">
  52.         <label>Email</label>
  53.         <input type="email" class="form-control" placeholder="enter email" name="email" value="<?php echo htmlspecialchars($email);?>">
  54.         <span class="error"><?php echo $emailError;  ?></span>
  55.     </div>
  56.     <div class="form-group">
  57.         <label>Confirm Email</label>
  58.         <input type="email" class="form-control" placeholder="confirm email" name="confirmemail" value="<?php echo htmlspecialchars($confirmemail);?>">
  59.         <span class="error"><?php echo $confirmemailError; ?></span>
  60.     </div>
  61.     <button type="submit" class="btn btn-default" name="register" value="submit">REGISTER</button> <!-- don't use camel case for form names -->
  62. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement