forked from COP4331-Group15/COP4331-Contact-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_in.php
More file actions
58 lines (47 loc) · 1.21 KB
/
Copy pathlog_in.php
File metadata and controls
58 lines (47 loc) · 1.21 KB
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
<?php
$inData = getRequestInfo();
$id = 0;
$firstName = "";
$lastName = "";
$conn = new mysqli("localhost", "Group15Admin", "ByVivec", "COP4331");
if( $conn->connect_error )
{
returnWithError( $conn->connect_error );
}
else
{
$stmt = $conn->prepare("SELECT ID,firstName,lastName FROM Users WHERE Login=? AND Password =?");
$stmt->bind_param("ss", $inData["login"], $inData["password"]);
$stmt->execute();
$result = $stmt->get_result();
if( $row = $result->fetch_assoc() )
{
returnWithInfo( $row['firstName'], $row['lastName'], $row['ID'] );
}
else
{
returnWithError("No Records Found");
}
$stmt->close();
$conn->close();
}
function getRequestInfo()
{
return json_decode(file_get_contents('php://input'), true);
}
function sendResultInfoAsJson( $obj )
{
header('Content-type: application/json');
echo $obj;
}
function returnWithError( $err )
{
$retValue = '{"id":0,"firstName":"","lastName":"","error":"' . $err . '"}';
sendResultInfoAsJson( $retValue );
}
function returnWithInfo( $firstName, $lastName, $id )
{
$retValue = '{"id":' . $id . ',"firstName":"' . $firstName . '","lastName":"' . $lastName . '","error":""}';
sendResultInfoAsJson( $retValue );
}
?>