· 6 years ago · Jun 25, 2019, 04:04 AM
1dataentry.html
2
3<html >
4<head>
5<title>Untitled Document</title>
6<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
7<script src="../angularscript/angular.min.js"></script>
8</head>
9
10<body ng-app="myApp">
11 <div ng-controller="mycontroller">
12 <form >
13 User id: <input type="text" ng-model="userid"/><br>
14 Name: <input type="text" ng-model="username"/><br>
15 Password: <input type="text" ng-model="pass"/><br>
16 Level: <input type="text" ng-model="level"/><br>
17 Status: <input type="text" ng-model="status"/><br>
18 <input type="submit" value="Add" ng-click="insertdata()"/>
19 <input type="submit" value="Update" ng-click="updatedata()"/>
20 <input type="submit" value="Delete" ng-click="deletedata()"/>
21 <input type="submit" value="Show" ng-click="showdata()"/>
22 </form>
23 {{successvalue}}
24
25 </div>
26
27
28 <div ng-controller="myCtrl">
29 <table border="1" width="50%">
30 <tr>
31 <th>User ID</th>
32 <th>Name</th>
33 <th>Password</th>
34 <th>Level</th>
35 <th>Status</th>
36 </tr>
37 <tr ng-repeat="data in myData">
38 <td ng-click="runctrl(data.userid)">{{data.userid}}</td>
39 <td>{{data.username}}</td>
40 <td>{{data.password}}</td>
41 <td>{{data.userlevel}}</td>
42 <td>{{data.status}}</td>
43 </tr>
44 </table>
45 </div>
46
47
48</body>
49</html>
50<script>
51 var app = angular.module('myApp', []);
52
53 app.controller('mycontroller', function($scope, $http, myService) {
54
55 $scope.insertdata=function(){
56 //alert($scope:name);
57 $scope.successvalue= "";
58 $http.post("insertdata.php", {'userid':$scope.userid, 'username':$scope.username, 'pass':$scope.pass, 'level':$scope.level, 'status':$scope.status }).
59 success(function(data, status, header, config){
60 $scope.successvalue = data;
61 });
62 }// Close insertdata function
63
64
65 $scope.updatedata=function(){
66 //alert($scope:name);
67 $scope.successvalue= "";
68 $http.post("updatedata.php", {'userid':$scope.userid, 'username':$scope.username, 'pass':$scope.pass, 'level':$scope.level, 'status':$scope.status }).
69 success(function(data, status, header, config){
70 $scope.successvalue = data;
71 });
72 }// Close updatedata function
73
74 $scope.deletedata=function(){
75 //alert($scope:name);
76 $scope.successvalue= "";
77 $http.post("deletedata.php", {'userid':$scope.userid, 'username':$scope.username, 'pass':$scope.pass, 'level':$scope.level, 'status':$scope.status }).
78 success(function(data, status, header, config){
79 $scope.successvalue = data;
80 });
81 }// Close deletedata function
82
83 $scope.showdata=function(){
84 //alert($scope:name);
85 $scope.successvalue= "";
86 $http.post("showdata2.php", {'userid':$scope.userid }).
87 success(function(data, status, header, config){
88
89 var obj = data;
90 $scope.userid = obj.userid;
91 $scope.username = obj.username;
92 $scope.pass = obj.password;
93 $scope.level = obj.userlevel;
94 $scope.status = obj.status;
95
96 $scope.successvalue = data;
97
98 });
99 }// Close showdata function
100
101 $scope.$on("myEvent", function () {
102 alert(myService.getUserid());
103 });
104
105
106 }); // Close Controller
107
108
109 app.controller('myCtrl', function($scope, $http, myService) {
110 //$scope.filename="getdata.php";
111 $scope.filename="usermaster.php";
112
113 $http.get($scope.filename)
114 .then(function(response) {
115 $scope.myData = response.data;
116
117 });
118
119 $scope.showdataclick=function(){
120 myService.setUserid('aaa')
121 alert(myService.getUserid() );
122 $scope.successvalue= "";
123 $http.post("showdata2.php", {'userid':$scope.userid }).
124 success(function(data, status, header, config){
125 var obj = data;
126 $scope.userid = obj.userid;
127 $scope.username = obj.username;
128 $scope.pass = obj.password;
129 $scope.level = obj.userlevel;
130 $scope.status = obj.status;
131 $scope.successvalue = data;
132 });
133 }// Close showdata function
134
135 $scope.runctrl = function(a){
136 myService.setUserid(a);
137 //alert(myService.getUserid());
138 $scope.$broadcast("myEvent");
139 };
140
141
142 });
143
144
145 app.factory('myService', function(){
146 var userid = null;//the object to hold our data
147 return {
148 getUserid:function(){
149 return userid;
150 },
151
152 setUserid:function(value){
153 userid = value;
154 }
155 }
156 });
157
158</script>
159
160-------------------------------------------------------------------------------------------------------------
161
162insertdata.php
163
164<?php
165$data = json_decode(file_get_contents("php://input"));
166$userid = $data->userid;
167$username = $data->username;
168$pass = $data->pass;
169$level = $data->level;
170$status = $data->status;
171
172
173mysql_connect("localhost", "root", "") or die ('Connection Failed!');
174mysql_select_db("mydatabase");
175
176$vSQL = " Insert Into usermaster ";
177$vSQL .= " ( userid, username, password, userlevel, status ) ";
178$vSQL .= " values( '$userid','$username','$pass','$level','$status' ) ";
179
180mysql_query($vSQL);
181
182echo $vSQL;
183?>
184
185
186
187----------------------------------------------------------------------------
188
189showdata2.php
190
191<?php
192header("Access-Control-Allow-Origin: *");
193header("Content-Type: application/json; charset=UTF-8");
194$data = json_decode(file_get_contents("php://input"));
195$userid = $data->userid;
196$conn = new mysqli("localhost", "root", "", "mydatabase");
197$result = $conn->query("SELECT userid, username, password, userlevel, status FROM usermaster where userid='$userid' ");
198
199$arr = array(); if($result->num_rows > 0){
200 while($row = $result->fetch_assoc()) {
201 $arr[] = $row;
202 }
203}
204//JSON-encode the response
205$conn->close();
206$json_response = json_encode($arr);
207echo substr( $json_response, 1, strlen($json_response)-2); // remove '[' and ']'
208?>
209
210
211------------------------------
212
213
214SQL
215
216
217
218CREATE TABLE IF NOT EXISTS `usermaster` (
219 `userid` varchar(50) NOT NULL,
220 `username` varchar(50) NOT NULL,
221 `password` varchar(30) NOT NULL,
222 `userlevel` int(11) NOT NULL,
223 `status` varchar(10) NOT NULL
224) ENGINE=MyISAM DEFAULT CHARSET=latin1;
225
226--
227-- Dumping data for table `usermaster`
228--
229
230INSERT INTO `usermaster` (`userid`, `username`, `password`, `userlevel`, `status`) VALUES
231('admin', 'Administrator', 'admin', 1, 'Active'),
232('vsk', 'VIGSHAKRI', '15', 1, 'Active'),
233('Orion', 'Belt Dee', '555', 2, 'InActive'),
234('krishnan', 'Krishnan', '5551', 1, 'Active'),
235('mike', 'Mike Mamba', '123', 3, 'Active'),
236('vels', 'Vetri', 'sharp', 1, 'Active'),
237('vsk1', '2', '22', 1, 'aa');