Advertisement
rozman50

Untitled

Jun 17th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. // AJAX - /js/functions.js at the bottom
  2. // Update state of checkboxes (RELAY, LED)
  3. $(function() {
  4.   // for every element state change, code below is executed
  5.   $(document).on("change", ":checkbox", function(){
  6.     // variables holds type and pin, state (0 or 1) and room ID
  7.     name = $(this).attr('name');
  8.     state = (Number(this.checked));
  9.     id_prostor = $(this).attr('title');
  10.     $.ajax({
  11.       type: "POST",
  12.       url: "updateState.php",
  13.       data: { name:name, state:state, id_prostor:id_prostor }
  14.     });
  15.   });
  16. });
  17.  
  18. // PHP - updateState.php
  19. <?php
  20. include 'connect.php';
  21.  
  22. $name = $_POST['name'];
  23. $state = $_POST['state'];
  24. $id_prostor = $_POST['id_prostor'];
  25.  
  26. $stmt = "UPDATE items set state = " . $state . "
  27. where item = '" . $name . "' and id_prostor = " . $id_prostor;
  28.  
  29. $res = mysqli_query($dbc, $stmt);
  30.  
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement