Advertisement
tidakasli

ini lohhh

Jan 30th, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.30 KB | None | 0 0
  1. connect.php
  2. <?php
  3.  
  4. class database
  5. {
  6.     var $host;
  7.     var $user;
  8.     var $password;
  9.     var $db_name;
  10.     var $mysqli;
  11.  
  12.     public function __construct($new_host, $new_user, $new_password, $new_db_name)
  13.     {
  14.         $this->host     = $new_host;
  15.         $this->user     = $new_user;
  16.         $this->password = $new_password;
  17.         $this->db_name  = $new_db_name;
  18.  
  19.         $this->mysqli = new mysqli($host, $user, $password, $db_name);
  20.         if($mysqli->connect_error)
  21.         {
  22.             die("Terjadi kesalahan");
  23.             exit;
  24.         }
  25.     }
  26. }
  27.  
  28. ?>
  29.  
  30. instantiate.php
  31. <?php
  32. function instantiate()
  33. {
  34.     $database = new database('localhost', 'root', '', 'tickit');
  35. }
  36. ?>
  37.  
  38. user.php
  39. <?php
  40. require 'functions/instantiate.php';
  41.  
  42. class user
  43. {
  44.     var $username;
  45.     private $password;
  46.     var $email;
  47.     var $firstname;
  48.     var $lasname;
  49.     var $address;
  50.     var $town;
  51.     var $country;
  52.     var $postcode;
  53.  
  54.     private $repeat_password;
  55.  
  56.     private $query;
  57.  
  58.  
  59.     function register($new_username, $new_password, $new_repeat_password, $new_email, $new_firstname, $new_lastname, $new_address, $new_town, $new_country, $new_postcode)
  60.     {
  61.         $this->username         = $new_username;
  62.         $this->password         = $new_password;
  63.         $this->repeat_password  = $new_repeat_password;
  64.         $this->email            = $new_email;
  65.         $this->firstname        = $new_firstname;
  66.         $this->lasname          = $new_lastname;
  67.         $this->address          = $new_address;
  68.         $this->town             = $new_town;
  69.         $this->country          = $new_country;
  70.         $this->postcode         = $new_postcode;
  71.  
  72.         $database = new database('localhost', 'root', '', 'tickit');
  73.         $selectUser = $database->prepare("SELECT username FROM user WHERE username=?");
  74.         $selectUser->bind_param('s', $this->username);
  75.         $selectUser->execute();
  76.         $selectUser->store_result();
  77.  
  78.         if(!$selectUser->num_rows)
  79.         {
  80.             if($this->password === $this->repeat_password)
  81.             {
  82.                 $inputUser = $mysqli->prepare("INSERT INTO user VALUES(?,?,?,?,?,?,?,?,?)");
  83.                 $inputUser->bind_param('sssssssss', $this->username, $this->password, $this->email, $this->firstname, $this->lastname, $this->address, $this->town, $this->country, $this->postcode);
  84.                 if($inputUser->execute())
  85.                 {
  86.                     header("location:login.php");
  87.                 }
  88.                 else
  89.                 {
  90.                     "Ada kesalahan saat mendaftar.";
  91.                 }
  92.             }
  93.             else
  94.             {
  95.                 echo "Password tidak sama.";
  96.             }
  97.         }
  98.         else
  99.         {
  100.             echo "Username tersebut sudah dipakai.";
  101.         }
  102.     }
  103. }
  104.  
  105. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement