Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- connect.php
- <?php
- class database
- {
- var $host;
- var $user;
- var $password;
- var $db_name;
- var $mysqli;
- public function __construct($new_host, $new_user, $new_password, $new_db_name)
- {
- $this->host = $new_host;
- $this->user = $new_user;
- $this->password = $new_password;
- $this->db_name = $new_db_name;
- $this->mysqli = new mysqli($host, $user, $password, $db_name);
- if($mysqli->connect_error)
- {
- die("Terjadi kesalahan");
- exit;
- }
- }
- }
- ?>
- instantiate.php
- <?php
- function instantiate()
- {
- $database = new database('localhost', 'root', '', 'tickit');
- }
- ?>
- user.php
- <?php
- require 'functions/instantiate.php';
- class user
- {
- var $username;
- private $password;
- var $email;
- var $firstname;
- var $lasname;
- var $address;
- var $town;
- var $country;
- var $postcode;
- private $repeat_password;
- private $query;
- function register($new_username, $new_password, $new_repeat_password, $new_email, $new_firstname, $new_lastname, $new_address, $new_town, $new_country, $new_postcode)
- {
- $this->username = $new_username;
- $this->password = $new_password;
- $this->repeat_password = $new_repeat_password;
- $this->email = $new_email;
- $this->firstname = $new_firstname;
- $this->lasname = $new_lastname;
- $this->address = $new_address;
- $this->town = $new_town;
- $this->country = $new_country;
- $this->postcode = $new_postcode;
- $database = new database('localhost', 'root', '', 'tickit');
- $selectUser = $database->prepare("SELECT username FROM user WHERE username=?");
- $selectUser->bind_param('s', $this->username);
- $selectUser->execute();
- $selectUser->store_result();
- if(!$selectUser->num_rows)
- {
- if($this->password === $this->repeat_password)
- {
- $inputUser = $mysqli->prepare("INSERT INTO user VALUES(?,?,?,?,?,?,?,?,?)");
- $inputUser->bind_param('sssssssss', $this->username, $this->password, $this->email, $this->firstname, $this->lastname, $this->address, $this->town, $this->country, $this->postcode);
- if($inputUser->execute())
- {
- header("location:login.php");
- }
- else
- {
- "Ada kesalahan saat mendaftar.";
- }
- }
- else
- {
- echo "Password tidak sama.";
- }
- }
- else
- {
- echo "Username tersebut sudah dipakai.";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement