From 9285724cc7c8f89665283b3b10797b211ab6cc2b Mon Sep 17 00:00:00 2001 From: Brian Flowers Date: Tue, 27 Sep 2016 01:30:32 -0400 Subject: [PATCH] Bugfixes on configuration saving --- configure.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/configure.php b/configure.php index 34e2d31..5fd29bb 100755 --- a/configure.php +++ b/configure.php @@ -26,20 +26,31 @@ if( isset($_POST) ) $setting = $id[2]; $value = $_POST[$key]; - $query = "INSERT INTO bdsmweb(host, attribute, $setting) ". - "VALUES (:host, :attribute, :value);"; - $stmt = $db->prepare($query); + + $params = array(':host' => $host, + ':attributes' => $attributes, + ':setting' => $setting, + ':value' => $value) + + $insert = "INSERT INTO bdsmweb(host, attribute) ". + "VALUES (:host, :attribute);" + $stmt = $db->prepare($insert); - if( !$stmt ) + if( $stmt ) { - print_r($db->errorInfo()); + $stmt->bindParam($params); + $stmt->execute(); + } + + $update = "UPDATE bdsmweb SET :setting = :value ". + "WHERE host = :host AND attribute = :attribute;"; + $stmt = $db->prepare($update); + + if( $stmt ) + { + $stmt->bindParam($params); + $stmt->execute(); } - - $stmt->bindParam(':host', $host); - $stmt->bindParam(':attribute', $attribute); - $stmt->bindParam(':value', $value); - - $stmt->execute(); } } ?> @@ -119,7 +130,6 @@ if( isset($_POST) ) query("SELECT DISTINCT host FROM MEASUREMENTS"); -print_r($db->errorInfo()); $hosts = Array(); while( $host = $result->fetch() ) @@ -144,7 +154,7 @@ foreach ($hosts as $host) echo " "; echo " $attribute"; echo " "; - echo " "; + echo " "; echo " - ". ""; echo " "; -- 1.8.3.1