Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.47 KB | None | 0 0
  1. registration page
  2.  
  3. <?php
  4. session_start();
  5. $errors = array();
  6.     if(isset($_POST['login'])){
  7.     $username =  $_POST['email'];
  8.     $password = $_POST['firstname'];
  9.     $firstname = $_POST['firstname'];
  10.     $lastname  =  $_POST['lastname'];
  11.     $age = $_POST['age'];
  12.     $address  = $_POST['address'];
  13.     $city = $_POST['city'];
  14.     $email  =  $_POST['email'];
  15.    
  16.     if(file_exists('../users/users.xml')){
  17.         $xml = simplexml_load_file('../users/users.xml');
  18.     }
  19.     foreach($xml->username as $user) if ($user == $username) $errors[] = 'Username already exists';
  20.    
  21.     if($username == ''){
  22.         $errors[] = 'Username is blank';
  23.     }
  24.    
  25.     if($email == ''){
  26.         $errors[] = 'Email is blank';
  27.     }
  28.     if($firstname == ''){
  29.         $errors[] = 'Firstname is blank';
  30.     }
  31.     if($lastname == ''){
  32.         $errors[] = 'lastname is blank';
  33.     }
  34.     if ($age <=15 || $age >=91){
  35.         $errors[] = 'Age must be between 16 and 90';
  36.     }
  37.     if ($address == ''){
  38.         $errors[] = 'Address is blank';
  39.     }
  40.     if ($city == ''){
  41.         $errors[] = 'City is blank';
  42.     }
  43.     if(count($errors) == 0){
  44.          
  45.         $xml = simplexml_load_file('../users/users.xml');
  46.         $nxml = new SimpleXMLElement($xml->asXML());
  47.         $nxml->addChild('username', $email);
  48.         $nxml->addChild('password', $firstname);
  49.         $nxml->addChild('firstname', $firstname);
  50.         $nxml->addChild('lastname', $lastname);
  51.         $nxml->addChild('age', $age);
  52.         $nxml->addChild('address', $address);
  53.         $nxml->addChild('city', $city);
  54.         $nxml->addChild('email', $email);
  55.         $nxml->asXML('../users/users.xml');
  56.         header('Location: products.php');
  57.        
  58.     }
  59. }
  60. require_once '../functions/functions1.php';?>
  61.  
  62. <?php echo render_header('dsPc: Shop Online');?>  
  63.  
  64. <?php echo render_nav();?>
  65.  
  66. <?php echo render_rego();?>
  67.  
  68. <?php echo render_footer();?>
  69.  
  70. rego function
  71.  
  72. function render_rego()
  73.    {
  74.     $output ="
  75.     <div id='bodywrap'>
  76.             <div id='text2'>
  77.                 <div class='pad'>";
  78.  
  79.    
  80. $output .="
  81.   <form action='' method=post name='registerform'>
  82.   ";    
  83.    if(count($errors) > 0){
  84.             echo '<ul>';
  85.             foreach($errors as $e){
  86.                 echo '<li>' . $e . '</li>';
  87.             }
  88.             echo '</ul>';
  89.         }
  90.         $output .="
  91.     <fieldset>
  92.     <legend>
  93.     Please Register you details:
  94.     </legend>
  95.     </fieldset>
  96.     <fieldset>
  97.         <label for='firstname'>First Name:</label>
  98.          <input type='text' name='firstname' size='20' />
  99.     </fieldset>
  100.      <fieldset>
  101.         <label for='lastname'>Last Name:</label>
  102.          <input type='text' name='lastname' size='20' />
  103.     </fieldset>
  104.     <fieldset>
  105.         <label for='age'>Age:</label>
  106.         <input type='text' name='age' size='20' />
  107.     </fieldset>
  108.     <fieldset>
  109.         <label for='address'>Address:</label>
  110.             <input type='text' name='address' size='20' />
  111.     </fieldset>
  112.     <fieldset>
  113.         <label for='city'>City:</label>
  114.             <input type='text' name='city' size='20' />
  115.     </fieldset>
  116.     <fieldset>
  117.         <label for='email'>Email:</label>
  118.             <input type='text' name='email' size='20' />
  119.     </fieldset>
  120.     <p class='submit'>
  121.             <input type='submit' name='login' value='Login' />
  122.     </p>
  123. </form>";
  124.         $output .='
  125.                 </div>
  126.             </div>
  127.         </div>
  128.     ';
  129.            return $output;
  130.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement