From c50a323c25a0787ba2051b19721983776a229615 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 5 Feb 2015 00:40:47 +0100 Subject: Initial commit --- include/contacts-edit.php | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 include/contacts-edit.php (limited to 'include/contacts-edit.php') diff --git a/include/contacts-edit.php b/include/contacts-edit.php new file mode 100644 index 0000000..9e7c606 --- /dev/null +++ b/include/contacts-edit.php @@ -0,0 +1,65 @@ +. + */ + +require_once('./conf.php'); + +$response = new response(); + +try { + $contact = new contact($_pdo, $_REQUEST['pk']); + + $name = explode('-', $_REQUEST['name']); + $what_to_edit = $name[count($name) - 1]; + switch ($what_to_edit) { + case 'name': + $response->success = $contact->setName($_REQUEST['value']); + break; + case 'email': + $response->success = $contact->setEmail($_REQUEST['value']); + break; + case 'address': + $response->success = $contact->setAddress($_REQUEST['value']); + break; + case 'postal_code': + $response->success = $contact->setPostalCode($_REQUEST['value']); + break; + case 'city': + $response->success = $contact->setCity($_REQUEST['value']); + break; + case 'country': + $response->success = $contact->setCountry($_REQUEST['value']); + break; + default: + $response->http_response_code(404); + $response->success = false; + } + if (!$response->success) { + $response->http_response_code(500); + $response->message = "The contact could not be edited due to an error."; + } +} catch (PDOException $e) { + $response->http_response_code(500); + $response->success = false; + $response->message = "The contact could not be edited due to a PDO error ({$e->getMessage()})."; +} catch (Exception $e) { + $response->http_response_code(404); + $response->success = false; + $response->message = "The contact could not be edited due to an exception."; +} +echo $response->message; \ No newline at end of file -- cgit v1.2.3