forked from KalebOTB/ContactManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
<?php | ||
|
||
$inData = getRequestInfo(); | ||
|
||
$userId = $inData["userId"]; | ||
$contactId = $inData["contactId"]; | ||
|
||
$conn = new mysqli("localhost", "TheManager", "COP4331", "ContactManager"); | ||
if( $conn->connect_error ) | ||
{ | ||
returnWithError( $conn->connect_error ); | ||
} | ||
else | ||
{ | ||
$sql = "DELETE FROM List WHERE ID = '$contactId' AND UserID = '$userId'"; | ||
//$stmt->execute(); | ||
//$result = $stmt->get_result(); | ||
if ($conn->query($sql) === TRUE) { | ||
echo "Record deleted successfully"; | ||
} else { | ||
echo "Error deleting record: " . $conn->error; | ||
} | ||
//$stmt->close(); | ||
$conn->close(); | ||
returnWithError(""); | ||
} | ||
|
||
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 = '{"error":"' . $err . '"}'; | ||
sendResultInfoAsJson( $retValue ); | ||
} | ||
|
||
//function returnWithInfo( $firstName, $lastName, $id ) | ||
//{ | ||
// $retValue = '{"id":' . $id . ',"firstName":"' . $firstName . '","lastName":"' . $lastName . '","error":""}'; | ||
// sendResultInfoAsJson( $retValue ); | ||
//} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
$inData = getRequestInfo(); | ||
|
||
$firstname = $inData["firstName"]; | ||
$lastname = $inData["lastName"]; | ||
$email = $inData["email"]; | ||
$phonenumber = $inData["phoneNumber"]; | ||
$login = $inData["login"]; | ||
$password = $inData["password"]; | ||
$id =0; | ||
|
||
$conn = new mysqli("localhost", "TheManager", "COP4331", "ContactManager"); | ||
if ($conn->connect_error) | ||
{ | ||
returnWithError( $conn->connect_error ); | ||
} | ||
else | ||
{ | ||
$sql = "INSERT INTO Users (FirstName,LastName,Email,PhoneNumber,Login,Password) | ||
VALUES('$firstname', '$lastname', '$email', '$phonenumber', '$login', '$password')"; | ||
|
||
if ($conn->query($sql) === TRUE) { | ||
echo "New user created successfully", "\n"; | ||
} | ||
else { | ||
echo "Error: " . $sql . "<br>" . $conn->error; | ||
} | ||
$stmt = $conn->prepare("SELECT ID FROM Users WHERE Login=? AND Password =?"); | ||
$stmt->bind_param("ss", $login, $password); | ||
$stmt->execute(); | ||
$result = $stmt->get_result(); | ||
|
||
if( $row = $result->fetch_assoc() ) | ||
{ | ||
returnWithInfo( $row['ID']); | ||
} | ||
else | ||
{ | ||
returnWithError("No Records Found"); | ||
} | ||
|
||
$stmt->close(); | ||
$conn->close(); | ||
returnWithError(""); | ||
} | ||
|
||
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 = '{"error":"' . $err . '"}'; | ||
sendResultInfoAsJson( $retValue ); | ||
} | ||
function returnWithInfo( $id ) | ||
{ | ||
$retValue = '{"id":' . $id . '}'; | ||
sendResultInfoAsJson( $retValue ); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
$inData = getRequestInfo(); | ||
|
||
$searchResults = ""; | ||
$searchCount = 0; | ||
$id = 0; | ||
|
||
$conn = new mysqli("localhost", "TheManager", "COP4331", "ContactManager"); | ||
if ($conn->connect_error) | ||
{ | ||
returnWithError( $conn->connect_error ); | ||
} | ||
else | ||
{ | ||
$stmt = $conn->prepare("SELECT firstName, ID FROM List WHERE firstName LIKE ? AND UserID=?"); | ||
$contactName = "%" . $inData["search"] . "%"; | ||
$stmt->bind_param("ss", $contactName, $inData["userId"]); | ||
$stmt->execute(); | ||
|
||
$result = $stmt->get_result(); | ||
|
||
while($row = $result->fetch_assoc()) | ||
{ | ||
if( $searchCount > 0 ) | ||
{ | ||
$searchResults .= ","; | ||
} | ||
$searchCount++; | ||
$searchResults .= '"' . $row["firstName"] . ' ' . $row["ID"] . '"'; | ||
} | ||
|
||
if( $searchCount == 0 ) | ||
{ | ||
returnWithError( "No Records Found" ); | ||
} | ||
|
||
$stmt->close(); | ||
$stmt = $conn->prepare("SELECT lastName, ID FROM List WHERE lastName LIKE ? AND UserID=?"); | ||
$contactName = "%" . $inData["search"] . "%"; | ||
$stmt->bind_param("ss", $contactName, $inData["userId"]); | ||
$stmt->execute(); | ||
|
||
$result = $stmt->get_result(); | ||
|
||
while($row = $result->fetch_assoc()) | ||
{ | ||
if( $searchCount > 0 ) | ||
{ | ||
$searchResults .= ","; | ||
} | ||
$searchCount++; | ||
$searchResults .= '"' . $row["lastName"] . ' ' . $row["ID"] . '"'; | ||
} | ||
|
||
if( $searchCount == 0 ) | ||
{ | ||
returnWithError( "No Records Found" ); | ||
} | ||
else | ||
{ | ||
returnWithInfo( $searchResults ); | ||
error($searchResults); | ||
} | ||
$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( $searchResults ) | ||
{ | ||
$retValue = '{"Contacts":[' . $searchResults . ']}'; | ||
sendResultInfoAsJson( $retValue ); | ||
} | ||
function error($searchResults) | ||
{ | ||
$retValue = '"error":""'; | ||
echo "\n"; | ||
sendResultInfoAsJson( $retValue ); | ||
} | ||
?> |