-
Notifications
You must be signed in to change notification settings - Fork 0
/
student.php
112 lines (109 loc) · 2.36 KB
/
student.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
<?php
$conn=mysqli_connect('localhost','root','','ajandphptesting');
$post=file_get_contents("php://input");
$ndata=json_decode($post);
$action=$ndata->action;
if($action=='get_student_list')
{
$sqry="select * from students";
$exe=mysqli_query($conn,$sqry);
$data=array();
if(mysqli_num_rows($exe)>0)
{
$data['reponse']='success';
while($row=mysqli_fetch_assoc($exe))
{
$data['list'][]=$row;
}
}
else
{
$data['reponse']='failed';
$data['list']=array();
}
$slist=json_encode($data);
echo $slist;
}
else if($action=="add_student_list")
{
$name=$ndata->name;
$email=$ndata->email;
$mbno=$ndata->mbno;
$address=$ndata->address;
$iquery="insert into students(NAME,EMAIL,MB_NO,ADDRESS) values('$name','$email','$mbno','$address')";
$iexe=mysqli_query($conn,$iquery);
$data=array();
if($iexe)
{
$data['response']='success';
$data['msg']="Student list Added successfully";
}
else{
$data['response']='failed';
$data['msg']="Student list not Added successfully".mysqli_error($conn);
}
echo json_encode($data);
}
else if($action=="get_student_data")
{
$id=$ndata->id;
$sqry="select * from students where ID='$id'";
$exe=mysqli_query($conn,$sqry);
$data=array();
if(mysqli_num_rows($exe)>0)
{
$data['response']='success';
while($row=mysqli_fetch_assoc($exe))
{
$data['list']=$row;
}
}
else
{
$data['response']='failed';
$data['list']=array();
}
$slist=json_encode($data);
echo $slist;
}
/*else if($action=="update_student_list")
{
$id=$ndata->ID;
$name=$ndata->NAME;
$email=$ndata->EMAIL;
$mbno=$ndata->MB_NO;
$address=$ndata->ADDRESS;
$uquery="update students set NAME='$name',EMAIL='$email',MB_NO='$mbno',ADDRESS='$address' where ID='$id'";
$uexe=mysqli_query($conn,$uquery);
$data=array();
if($uexe)
{
$data['response']='success';
$data['msg']="Student Details Updated successfully";
}
else{
$data['response']='failed';
$data['msg']="Student Details not Updated successfully".mysqli_error($conn);
}
echo json_encode($data);
}*/
else if($action=="delete_student_data")
{
$id=$ndata->id;
$dqry="delete from students where ID='$id'";
$dexe=mysqli_query($conn,$dqry);
$data=array();
if($dexe)
{
$data['response']='success';
$data['msg']="Student Removed successfully";
}
else
{
$data['response']='failed';
$data['msg']="Student not Removed".mysqli_error($conn);;
}
$slist=json_encode($data);
echo $slist;
}
?>