function postHandler() { if (isset($_GET['updateId'])) { //Hack for PUT putHandler($_GET['updateId']); } elseif (isset($_POST['firstname']) && isset($_POST['lastname'])) { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $query = "INSERT INTO authors(firstname, lastname) VALUES ('{$firstname}', '{$lastname}')"; $result = $mysqli->query($query) or die($mysqli->error . __LINE__); $result = $mysqli->affected_rows; echo $json_response = json_encode($result); } else { die("Body must contain firstname and lastname"); } }
function postHandler() { if (isset($_GET['updateId'])) { //Hack for PUT putHandler($_GET['updateId']); } elseif (isset($_POST['title']) && isset($_POST['story']) && isset($_POST['authorId']) && isset($_POST['date'])) { $title = $_POST['title']; $story = $_POST['story']; $authorId = $_POST['authorId']; $date = $_POST['date']; $query = "INSERT INTO news(title, story, authorId, date) VALUES ('{$title}', '{$story}', '{$authorId}', '{$date}')"; $result = $mysqli->query($query) or die($mysqli->error . __LINE__); $result = $mysqli->affected_rows; echo $json_response = json_encode($result); } else { die("Body must contain title, story, auhtorId and date"); } }