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
4 changed files
with
212 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,47 @@ | ||
<?php | ||
$inData = getRequestInfo(); | ||
|
||
$firstName = $inData["firstName"]; | ||
$lastName = $inData["lastName"]; | ||
$email = $inData["email"]; | ||
$phoneNumber = $inData["phoneNumber"]; | ||
$userId = $inData["userId"]; | ||
|
||
$conn = new mysqli("localhost", "TheManager", "COP4331", "ContactManager"); | ||
if ($conn->connect_error) | ||
{ | ||
returnWithError( $conn->connect_error ); | ||
} | ||
else | ||
{ | ||
$sql = "INSERT INTO List (FirstName, LastName, Email, PhoneNumber, UserID) | ||
VALUES ('$firstName', '$lastName', '$email', '$phoneNumber', '$userId' )"; | ||
|
||
if ($conn->query($sql) === TRUE) { | ||
echo "New contact created successfully"; | ||
} | ||
else { | ||
echo "Error: " . $sql . "<br>" . $conn->error; | ||
} | ||
$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 ); | ||
} | ||
|
||
?> |
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,48 @@ | ||
<?php | ||
$inData = getRequestInfo(); | ||
|
||
$firstName = $inData["firstName"]; | ||
$lastName = $inData["lastName"]; | ||
$email = $inData["email"]; | ||
$phoneNumber = $inData["phoneNumber"]; | ||
$userId = $inData["userId"]; | ||
$contactId = $inData["contactId"]; | ||
|
||
$conn = new mysqli("localhost", "TheManager", "COP4331", "ContactManager"); | ||
if ($conn->connect_error) | ||
{ | ||
returnWithError( $conn->connect_error ); | ||
} | ||
else | ||
{ | ||
$sql = "UPDATE List SET firstname= '$firstName', lastname='$lastName', email ='$email', phoneNumber = '$phoneNumber' | ||
WHERE ID = '$contactId' AND UserID = '$userId'"; | ||
|
||
if ($conn->query($sql) === TRUE) { | ||
echo "Contact update successful"; | ||
} | ||
else { | ||
echo "Error: " . $sql . "<br>" . $conn->error; | ||
} | ||
$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 ); | ||
} | ||
|
||
?> |
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,58 @@ | ||
|
||
<?php | ||
|
||
$inData = getRequestInfo(); | ||
|
||
$id = 0; | ||
$firstName = ""; | ||
$lastName = ""; | ||
|
||
$conn = new mysqli("localhost", "TheManager", "COP4331", "ContactManager"); | ||
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 ); | ||
} | ||
|
||
?> |
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,59 @@ | ||
|
||
<?php | ||
|
||
$inData = getRequestInfo(); | ||
|
||
$firstName = ""; | ||
$lastName = ""; | ||
$email = ""; | ||
$phoneNumber = 0; | ||
|
||
$conn = new mysqli("localhost", "TheManager", "COP4331", "ContactManager"); | ||
if( $conn->connect_error ) | ||
{ | ||
returnWithError( $conn->connect_error ); | ||
} | ||
else | ||
{ | ||
$stmt = $conn->prepare("SELECT firstName,lastName,email,phoneNumber FROM List WHERE UserID=? AND ID =?"); | ||
$stmt->bind_param("ii", $inData["userId"], $inData["contactId"]); | ||
$stmt->execute(); | ||
$result = $stmt->get_result(); | ||
|
||
if( $row = $result->fetch_assoc() ) | ||
{ | ||
returnWithInfo( $row['firstName'], $row['lastName'], $row['email'], $row['phoneNumber'] ); | ||
} | ||
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 = '{"firstName":"","lastName":"", "email":"", "phoneNumber":"", "error":"' . $err . '"}'; | ||
sendResultInfoAsJson( $retValue ); | ||
} | ||
|
||
function returnWithInfo( $firstName, $lastName, $email, $phoneNumber ) | ||
{ | ||
$retValue = '{"firstName":"' . $firstName . '","lastName":"' . $lastName . '", "email":"' . $email . '", "phoneNumber":"' . $phoneNumber . '","error":""}'; | ||
sendResultInfoAsJson( $retValue ); | ||
} | ||
|
||
?> |