-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdao.php
More file actions
143 lines (130 loc) · 2.92 KB
/
dao.php
File metadata and controls
143 lines (130 loc) · 2.92 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
include 'db.php' ;
function login($user){
$con=$GLOBALS['con'];
$n=$user['name'];
$p=$user['pass'];
$e_p=md5($p);
$sql="select name,password from users where name=? and password=?";
$st=$con->prepare($sql);
$st->bind_param("ss",$n,$e_p);
if($st->execute()){
$res=$st->get_result();
if($res->num_rows>0){
return true;
}
}
else{
echo $con->error;
}
}
function addUser($user){
$n=$user['name'];
$e=$user['email'];
$p=$user['pass'];
$e_p=md5($p);
$con=$GLOBALS['con'];
$sql="insert into users values (null,?,?,?)";
$st=$con->prepare($sql);
$st->bind_param("sss",$n, $e, $e_p);
if($st->execute()){
//header("location:welcome.php?n=$name");
return true;
}
else{
return false;
//echo $con->error;
}
}
function getUsers(){
$con=$GLOBALS['con'];
$sql="select * from users";
$result=$con->query($sql);
$users=array();
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$users[]=$row;
}
}
// echo "<pre>";
// print_r($users);
// echo "</pre>";
return $users;
}
function getUser($id){
$con=$GLOBALS['con'];
$sql="select * from users where id=?";
$st=$con->prepare($sql);
$st->bind_param("i",$id);
if($st->execute()){
$result=$st->get_result();
if($result->num_rows > 0){
if($row=$result->fetch_assoc()){
// echo "<pre>";
// print_r($row);
// echo "</pre>";
return $row;
}
}
}
else{
echo $con->error;
}
}
function deleteUser($id){
$con=$GLOBALS['con'];
$sql="delete from users where id=?";
$st=$con->prepare($sql);
$st->bind_param("i",$id);
if($st->execute()){
return true;
}
else{
echo $con->error;
}
}
function editUser($user){
$con=$GLOBALS['con'];
$name=$user['name'];
$email=$user['email'];
$id=$user['id'];
$sql="update users set name=?,email=? where id=?";
$st=$con->prepare($sql);
$st->bind_param("ssi",$name,$email,$id);
if($st->execute()){
return true;
}
else{
echo $con->error;
}
}
function uploadFile($name){
$con=$GLOBALS['con'];
$sql="insert into profile values (null,?)";
$st=$con->prepare($sql);
$st->bind_param("s",$name);
if($st->execute()){
//header("location:welcome.php?n=$name");
return true;
}
else{
return false;
//echo $con->error;
}
}
function getFiles(){
$con=$GLOBALS['con'];
$sql="select * from profile";
$result=$con->query($sql);
$img=array();
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$img[]=$row;
}
}
// echo "<pre>";
// print_r($users);
// echo "</pre>";
return $img;
}
?>