-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
114 lines (96 loc) · 3.65 KB
/
index.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
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
<?php
session_start();
define('DB_SERVER','localhost');
define('DB_USER','Rca250');
define('DB_PASS' ,'Edenabc');
define('DB_NAME', 'Crud');
class Database{
function __construct(){
$con=mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
$this->dbh=$con;
//checking the connection
if(mysqli_connect_error()){
echo "Connection Failed".mysqli_connect_error();
}
}
// Data insertion
public function insert($firstname,$lastname,$telephone,$gender,$nationality,$username,$email,$password){
$insertUser=mysqli_query($this->dbh,"insert into User(firstname,lastname,telephone,gender,nationality,username,email,passoword) values('$firstname','$lastname','$telephone','$nationality','$gender','$username','$email','$password')");
return $insertUser;
}
//Data read
public function read(){
$result=mysqli_query($this->dbh,"select * from User");
return $result;
}
//Data one record read
public function readOne($userId){
$readUser=mysqli_query($this->dbh,"select * from User where userid=$userId");
return $readUser;
}
//Data update
public function update($userId,$firstname,$lastname,$telephone,$gender,$nationality,$username,$email,$password){
$UpdateUser=mysqli_query($this->dbh,"update User set userId='$userId', firstname='$firstname',lastname='$lastname',telephone='$telephone',gender='$gender',nationality='$nationality',username='$username',email='$email',passoword='$password'");
return $UpdateUser;
}
//Data deletion function
public function delete($deleteid){
$deleteUser=mysqli_query($this->dbh,"delete from User where userid=$deleteid");
return $deleteUser;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<title>Document</title>
</head>
<body>
<table>
<tr>
<th>FirstName</th>
<th>lastName</th>
<th>telephone</th>
<th>Gender</th>
<th>Nationality</th>
<th>Username</th>
<th>Email</th>
<th>password</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</table>
</body>
</html>
<?php
$fetchdata=new Database();
$sql=$fetchdata->read();
$count=1;
while($row=mysqli_fetch_array($sql)){
?>
<tr>
<td><?php echo $count ;?></td>
<!-- <td><?php echo $row['userId'];?></td> -->
<td><?php echo $row['firstname'];?></td>
<td><?php echo $row['lastname'];?></td>
<td><?php echo $row['telephone'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['nationality'];?></td>
<td><?php echo $row['username'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['passoword'];?></td>
<td><a href="update.php?userId=<?php echo $row['userId'];?>"><button class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-pencil"></span>Update</button></a></td>
<td><a href="delete.php?del=<?php echo $row['userId'];?>"><button type="submit" class="btn btn-danger ">Delete</button></a></td>
</tr>
<?php
$count++;
};
?>