View difference between Paste ID: swQ9sPWz and n4gh71SJ
SHOW: | | - or go back to the newest paste.
1
<!---
2
awalannya sudah salah sebenarnya.. tetapi saya juga salah kl memperbaiki seperti ini
3
at least jalan.. tp ini bukan solusi ya..
4
--->
5
connect.php
6
<?php
7
8
class database
9
{
10
	var $host;
11
	var $user;
12
	var $password;
13
	var $db_name;
14
	var $mysqli;
15
16
	public function __construct($new_host, $new_user, $new_password, $new_db_name)
17
	{
18
		$this->host 	= $new_host;
19-
		$this->mysqli = new mysqli($host, $user, $password, $db_name);
19+
20
		$this->password = $new_password;
21
		$this->db_name 	= $new_db_name;
22
23
		$mysqli = new mysqli($host, $user, $password, $db_name);
24
		if($mysqli->connect_error)
25
		{
26
			die("Terjadi kesalahan");
27
			exit;
28
		}else{
29
			return $mysqli;
30
31
		}
32
	}
33
}
34
35
?>
36
37
instantiate.php
38
<?php
39
function instantiate()
40
{
41
	$database = new database('localhost', 'root', '', 'tickit');
42
}
43
?>
44
45
user.php
46
<?php
47
require 'functions/instantiate.php';
48
49
class user 
50
{
51
	var $username;
52
	private $password;
53
	var $email;
54
	var $firstname;
55
	var $lasname;
56
	var $address;
57
	var $town;
58
	var $country;
59
	var $postcode;
60
61
	private $repeat_password;
62
63
	private $query;
64
65
66
	function register($new_username, $new_password, $new_repeat_password, $new_email, $new_firstname, $new_lastname, $new_address, $new_town, $new_country, $new_postcode)
67
	{
68
		$this->username 		= $new_username;
69
		$this->password			= $new_password;
70
		$this->repeat_password	= $new_repeat_password;
71
		$this->email 			= $new_email;
72
		$this->firstname 		= $new_firstname;
73
		$this->lasname 			= $new_lastname;
74
		$this->address 			= $new_address;
75
		$this->town 			= $new_town;
76
		$this->country 			= $new_country;
77
		$this->postcode 		= $new_postcode;
78
79
		$database = new database('localhost', 'root', '', 'tickit');
80
		$selectUser = $database->prepare("SELECT username FROM user WHERE username=?");
81
		$selectUser->bind_param('s', $this->username);
82
		$selectUser->execute();
83
		$selectUser->store_result();
84
85
		if(!$selectUser->num_rows)
86
		{
87
			if($this->password === $this->repeat_password)
88
			{
89
				$inputUser = $mysqli->prepare("INSERT INTO user VALUES(?,?,?,?,?,?,?,?,?)");
90
				$inputUser->bind_param('sssssssss', $this->username, $this->password, $this->email, $this->firstname, $this->lastname, $this->address, $this->town, $this->country, $this->postcode);
91
				if($inputUser->execute())
92
				{
93
					header("location:login.php");
94
				}
95
				else
96
				{
97
					"Ada kesalahan saat mendaftar.";
98
				}
99
			}
100
			else
101
			{
102
				echo "Password tidak sama.";
103
			}
104
		}
105
		else
106
		{
107
			echo "Username tersebut sudah dipakai.";
108
		}
109
	}
110
}
111
112
?>