-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.php
55 lines (49 loc) · 2.2 KB
/
user.php
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
<?php
class user{
//private database object
private $db;
//constructor to initialize private variable to the database connection
function __construct($conn){
$this->db = $conn;
}
public function insertUser($user_name,$contact,$e_mail,$user_password,$qualification){
try {
$result = $this->getUserbyUsername($user_name);
if ($result['num']>0){
return false;
}else{
$new_password = md5($user_password.$user_name);
$sql= "INSERT INTO users(user_name,contact,e_mail,user_password,qualification) values(:username,:contact,:email,:password,:qualification)";
$stmt= $this->db->prepare($sql);
$stmt->bindparam(':username',$user_name);
$stmt->bindparam(':username',$contact);
$stmt->bindparam(':password',$e_mail);
$stmt->bindparam(':password',$new_password);
$stmt->bindparam(':username',$qualification);
$stmt->execute();
return true;
}
} catch (PDOException $e) {
echo $e->getMessage();
return false;
}
}
public function getUser($user_name,$user_password){
$sql = "SELECT * FROM users where user_name = :user_name and user_password = :user_password";
$stmt = $this->db->prepare($sql);
$stmt->bindparam(':user_name',$user_name);
$stmt->bindparam(':user_password',$user_password);
$stmt->execute();
$result = $stmt->fetch();
return $result;
}
public function getUserbyUsername($username){
$sql = "SELECT count(*) as num FROM users where user_name = :user_name";
$stmt = $this->db->prepare($sql);
$stmt->bindparam(':user_name',$user_name);
$stmt->execute();
$result = $stmt->fetch();
return $result;
}
}
?>