Logic to handle "DELETE Candidates ID"
[asis23-votoe-server.git] / post_candidates.php
blob8dccb80bee087d635e677281a88ccfc968e167d7
1 <?php
3 function handle_request($id, $input) {
4 $input = json_decode($input, true);
6 $db = new SQLite3('database.sqlite');
7 $db->exec("INSERT INTO candidatos (nombre) VALUES ('{$input['name']}')");
8 $id = $db->lastInsertRowID();
9 $candidate = $db->querySingle("SELECT id, nombre FROM candidatos WHERE id = {$id}", true);
10 $db->close();
12 echo json_encode([
13 'id' => $candidate['id'],
14 'name' => $candidate['nombre'],
15 ]);