7 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); |
7 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); |
8 if (! $connect) { |
8 if (! $connect) { |
9 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
9 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
10 } |
10 } |
11 mysqli_set_charset($connect, "utf8" ); |
11 mysqli_set_charset($connect, "utf8" ); |
|
12 |
|
13 $response = array( |
|
14 'error' => false, |
|
15 'msg' => 'Ok', |
|
16 ); |
12 |
17 |
13 if (isset($_POST['insert']) || isset($_POST['update'])) { |
18 if (isset($_POST['insert']) || isset($_POST['update'])) { |
14 if (isset($_POST['insert'])) { |
19 if (isset($_POST['insert'])) { |
15 $sql = "INSERT INTO `profile_water` SET "; |
20 $sql = "INSERT INTO `profile_water` SET "; |
16 } |
21 } |
32 $sql .= "';"; |
37 $sql .= "';"; |
33 } |
38 } |
34 if (isset($_POST['update'])) { |
39 if (isset($_POST['update'])) { |
35 $sql .= "' WHERE record='" . $_POST['record'] . "';"; |
40 $sql .= "' WHERE record='" . $_POST['record'] . "';"; |
36 } |
41 } |
37 //syslog(LOG_NOTICE, $sql); |
|
38 |
|
39 $result = mysqli_query($connect, $sql); |
42 $result = mysqli_query($connect, $sql); |
40 if (! $result) { |
43 if (! $result) { |
41 syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect)); |
44 syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect)); |
42 //} else { |
45 $response['error'] = true; |
43 // if (isset($_POST['update'])) { |
46 $response['msg'] = "SQL fout: ".mysqli_error($connect); |
44 // syslog(LOG_NOTICE, "db_profile_water: updated record ".$_POST['record']); |
47 } |
45 // } else { |
48 exit(json_encode($response)); |
46 // $lastid = mysqli_insert_id($connect); |
|
47 // syslog(LOG_NOTICE, "db_profile_water: inserted record ".$lastid); |
|
48 // } |
|
49 } |
|
50 echo $result; |
|
51 |
49 |
52 } else if (isset($_POST['delete'])) { |
50 } else if (isset($_POST['delete'])) { |
53 // DELETE COMMAND |
51 // DELETE COMMAND |
54 $sql = "DELETE FROM `profile_water` WHERE record='".$_POST['record']."';"; |
52 $sql = "DELETE FROM `profile_water` WHERE record='".$_POST['record']."';"; |
55 $result = mysqli_query($connect, $sql); |
53 $result = mysqli_query($connect, $sql); |
56 if (! $result) { |
54 if (! $result) { |
57 syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect)); |
55 syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect)); |
58 } else { |
56 $response['error'] = true; |
59 syslog(LOG_NOTICE, "db_profile_water: deleted record ".$_POST['record']); |
57 $response['msg'] = "SQL fout: ".mysqli_error($connect); |
60 } |
58 } |
61 echo $result; |
59 exit(json_encode($response)); |
62 |
60 |
63 } else { |
61 } else { |
64 // SELECT COMMAND |
62 // SELECT COMMAND |
65 $query = "SELECT * FROM profile_water ORDER BY name"; |
63 $query = "SELECT * FROM profile_water ORDER BY name"; |
66 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
64 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
78 'notes' => $row['notes'], |
76 'notes' => $row['notes'], |
79 'total_alkalinity' => $row['total_alkalinity'] |
77 'total_alkalinity' => $row['total_alkalinity'] |
80 ); |
78 ); |
81 } |
79 } |
82 header("Content-type: application/json"); |
80 header("Content-type: application/json"); |
83 echo json_encode($waters); |
81 exit(json_encode($waters)); |
84 } |
82 } |
|
83 |
|
84 syslog(LOG_NOTICE, "db_profile_water: missing arguments"); |
|
85 $response['error'] = true; |
|
86 $response['msg'] = "missing arguments"; |
|
87 echo json_encode($response); |
|
88 |
85 ?> |
89 ?> |