]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | <?php\r |
2 | \r | |
3 | include '../connection.php';\r | |
4 | \r | |
5 | try {\r | |
6 | $key = $_POST['key'];\r | |
7 | $value = $_POST['value'];\r | |
8 | \r | |
9 | // first read the config table to see if a config already exists for this key\r | |
10 | $statement = $db->prepare("select value from config where key = '$key'");\r | |
11 | if(!$statement->execute()) {\r | |
12 | throw new Exception(implode(', ', $statement->errorInfo()));\r | |
13 | }\r | |
14 | if(!$statement->fetch(PDO::FETCH_COLUMN)) {\r | |
15 | $sql = "insert into config (key, value) values('$key', '$value')";\r | |
16 | } else {\r | |
17 | $sql = "update config set value = '$value' where key = '$key'";\r | |
18 | }\r | |
19 | \r | |
20 | $statement = $db->prepare($sql);\r | |
21 | if(!$statement->execute()) {\r | |
22 | throw new Exception(implode(', ', $statement->errorInfo()));\r | |
23 | }\r | |
24 | $jsonResult = array('success' => true);\r | |
25 | } catch(Exception $e) {\r | |
26 | $jsonResult = array(\r | |
27 | 'success' => false,\r | |
28 | 'message' => $e->getMessage()\r | |
29 | );\r | |
30 | }\r | |
31 | \r | |
32 | echo json_encode($jsonResult);\r | |
33 | \r | |
34 | ?> |