Bugfixes on configuration saving
authorBrian Flowers <git-admn@bsflowers.net>
Tue, 27 Sep 2016 05:30:32 +0000 (01:30 -0400)
committerBrian Flowers <git-admn@bsflowers.net>
Tue, 27 Sep 2016 05:30:32 +0000 (01:30 -0400)
configure.php

index 34e2d31..5fd29bb 100755 (executable)
@@ -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) )
       </tr>
 <?php
 $result = $db->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 "      <tr>";
       echo "        <td>$attribute</td>";
       echo "        <td><input type='text' name='$host|$attribute|name' value='".$values['name']."' /></td>";
-      echo "        <td><input type='checkbox' name='$host|$attribute|graph' ".$values['name']?"checked":""."/></td>";
+      echo "        <td><input type='checkbox' name='$host|$attribute|graph' ".($values['name']?"checked":"")."/></td>";
       echo "        <td><input type='text' name='$host|$attribute|minimum' value='".$values['minimum']."' class='short'/> - ".
                     "<input type='text' name='$host|$attribute|maximum' value='".$values['maximum']."' class='short'/></td>";
       echo "        <td><input type='text' name='$host|$attribute|duration' value='".$values['duration']."' class='short' /></td>";