-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex1.php
149 lines (144 loc) · 4.44 KB
/
index1.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
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
144
145
146
147
148
149
<!DOCTYPE html>
<html>
<head>
<title>CRUD</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
var editIcon = "<button>Edit</button>";
$(document).ready(function() {
getAllUsers()
$("#register").click(function() {
$.ajax({
type: "POST",
url: "http://localhost/MysqlCRUD/register.php",
success: function(result) {
if(result.resultCode == "Success") {
$("#loading").html(result.message);
$("#user-table").css("visibility","visible");
$('#user-table tbody').append("<tr><td>" +result.id+ "</td><td>" +result.email+ "</td><td>" +result.password+ "</td></tr> ");
} else {
$("#snackbar").html(result.resultCode);
$("#snackbar").attr('class','show');
setTimeout(function(){
$("#snackbar").attr('class','');
}, 3000);
}
},
data: $("#user_detail_form_data").serialize(),
error: function() {
$('#user-table').html('<p>An error has occurred</p>');
},
});
});
function getAllUsers() {
$.ajax({
type: "GET",
url: "http://localhost/MysqlCRUD/display.php",
success: function(result) {
if(result.resultCode == "Success") {
$("#loading").html("Loaded the table");
$("#user-table").css("visibility","visible");
for(var i = 0; i < result.records.length; i++) {
$('#user-table tbody').append(
"<tr><td>" +result.records[i].id+ "</td><td>" +
result.records[i].email+
"</td><td>" +
result.records[i].password+
"</td><td>" +
editIcon +
"</td></tr>");
}
} else {
$("#loading").html(result.message);
$("#snackbar").html(result.message);
$("#snackbar").attr('class','show');
setTimeout(function(){
$("#snackbar").attr('class','');
}, 3000);
}
},
error: function() {
$('#user-table').html('<p>An error has occurred</p>');
},
});
}
});
</script>
<style type="text/css">
#snackbar {
visibility: hidden;
min-width: 250px;
margin-left: -125px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 2px;
padding: 16px;
position: fixed;
z-index: 1;
left: 50%;
top: 30px; /*make it as bottom if you want to show in bottom*/
font-size: 17px;
}
#snackbar.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@-webkit-keyframes fadein {
from {top: 0; opacity: 0;} /*make it as bottom if you want to show in bottom*/
to {top: 30px; opacity: 1;}
}
@keyframes fadein {
from {top: 0; opacity: 0;}
to {top: 30px; opacity: 1;}
}
@-webkit-keyframes fadeout {
from {top: 30px; opacity: 1;}
to {top: 0; opacity: 0;}
}
@keyframes fadeout {
from {top: 30px; opacity: 1;}
to {top: 0; opacity: 0;}
}
</style>
</head>
<body>
<div class="container">
<h2>Registration</h2>
<form id = "user_detail_form_data">
<div class="form-group">
<label for="email">Email:</label>
<div id="snackbar"></div>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email" required>
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="password" required>
</div>
<button id = "register" type="button" class="btn btn-primary">Submit</button>
</form>
</div>
<div class = "container">
<div class = "form-group"><br><br>
<div class = "table" id = "loading">Loading ...</div>
<table class = "table table-border" id = "user-table" style = "visibility: hidden;">
<thead>
<th>id</th>
<th>email</th>
<th>password</th>
<th>Update</th>
<th>Delete</th>
</thead>
<tbody>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>