-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.php
More file actions
112 lines (111 loc) · 3.26 KB
/
user.php
File metadata and controls
112 lines (111 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
require_once ("database.php");
class User {
public $id;
public $username;
public $password;
public $name;
public $address;
public $email;
public $phone;
public $score;
public $collegeid;
public $college;
public $city;
public $country;
public function __construct() {
}
public function insert() {
global $database;
$database->prepare_statement ( "INSERT INTO user VALUES (NULL,?,?,?,?,?,?,?,?,?,?,?,NULL)" );
if ($database->stmt) {
$database->stmt->bind_param ( 'ssssssissss', $this->username, $this->password, $this->name, $this->address, $this->email, $this->phone, $this->score, $this->collegeid, $this->college, $this->city, $this->country );
$flag = $database->execute_statement ();
if (! $flag) {
echo "MySQL error: " . $database->mysqli_error ();
return false;
} else {
return true;
}
} else {
echo "MySQL error: " . $database->mysqli_error ();
return false;
}
}
public static function authenticate($username = "", $password = "") {
global $database;
$database->prepare_statement ( "SELECT userid FROM user WHERE username = ? AND password = ?" );
if ($database->stmt) {
$database->stmt->bind_param ( 'ss', $username, $password );
$database->execute_statement ();
$database->stmt->bind_result ( $i );
$found = $database->stmt->fetch ();
$database->stmt->close ();
return $found ? $i : false;
} else {
echo "MySQL error: " . $database->mysqli_error ();
return false;
}
}
public static function find_by_id($id) {
global $database;
$database->prepare_statement ( "SELECT * FROM user WHERE userid = ?" );
if ($database->stmt) {
$database->stmt->bind_param ( 'i', $id );
$database->execute_statement ();
$database->stmt->bind_result ( $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $c9, $c10, $c11, $c12, $c13 );
$found = $database->stmt->fetch ();
$user = new self ();
$user->id = $c1;
$user->username = $c2;
$user->password = $c3;
$user->name = $c4;
$user->address = $c5;
$user->email = $c6;
$user->phone = $c7;
$user->score = $c8;
$user->collegeid = $c9;
$user->college = $c10;
$user->city = $c11;
$user->country = $c12;
$user->timestamp = $c13;
$database->stmt->close ();
return $found ? $user : false;
} else {
echo "MySQL error: " . $database->mysqli_error ();
return false;
}
}
public static function show_top() {
global $database;
$database->prepare_statement ( "SELECT * FROM user where userid<>1 and userid<>2 and userid<>3 and userid<>4 ORDER BY score desc,username, UNIX_TIMESTAMP(timestamp) " );
if ($database->stmt) {
$database->execute_statement ();
$database->stmt->bind_result ( $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $c9, $c10, $c11, $c12, $c13 );
$users = array ();
$ii = 0;
while ( $database->stmt->fetch () ) {
$user = new self ();
$user->id = $c1;
$user->username = $c2;
$user->password = $c3;
$user->name = $c4;
$user->address = $c5;
$user->email = $c6;
$user->phone = $c7;
$user->score = $c8;
$user->collegeid = $c9;
$user->college = $c10;
$user->city = $c11;
$user->country = $c12;
$users [$ii] = $user;
$ii ++;
}
$database->stmt->close ();
return $users;
} else {
echo "MySQL error: " . $database->mysqli_error ();
return false;
}
}
}