forked from aniket-cr/research-bros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab_operations.php
40 lines (39 loc) · 991 Bytes
/
lab_operations.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
<?php
include_once('config.php');
$emailID = $_REQUEST['emailID'];
$add_lab = $_REQUEST['add_lab'];
$connect = mysqli_connect($servername,$username,$password,$dbname);
if($add_lab == 1) //a new lab has to be added
{
$name = $_REQUEST['name'];
$description = $_REQUEST['description'];
$query = "SELECT max(labID) as c FROM labs;";
echo $query;
$result = mysqli_query($connect,$query);
if(mysqli_num_rows($result) == 0)
{
$id = 1;
}
else
{
echo "in else";
$result = mysqli_fetch_array($result);
$id = $result['c'] + 1;
}
$query = "INSERT INTO labs(labID,universityID,admin,name,description)
VALUES($id,1,'$emailID','$name','$description');";
echo $query;
$result = mysqli_query($connect,$query);
}
if($add_lab == 0) //display all labs
{
$query = "SELECT * FROM labs;";
$result = mysqli_query($connect,$query);
$json = array();
while($res = mysqli_fetch_array($result))
{
$json[] = $res;
}
echo json_encode($json);
}
?>