Advertisement
Guest User

producten

a guest
Dec 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. producten.php
  2.  
  3. <?php
  4. include_once("header.php");
  5. include_once("functions.php");
  6. include_once("top.php");
  7. ?>
  8. <?php
  9. $show_voorraads = show_producten(); ?>
  10.  
  11. <div class="row" style="margin-top: 50px;">
  12. <div class="col-6 col-md-4">
  13. <?php include_once("sidebar.php"); ?>
  14. </div>
  15.  
  16.  
  17. <div class="col-12 col-sm-6 col-md-8">
  18.  
  19. <form class="form-horizontal" role="form" method="POST" action="producten.php">
  20.  
  21. <div class="form-group">
  22. <div class="col-md-3">
  23. <label>Locatiecode</label>
  24. <input id="locatiecode" type="text" class="form-control" name="Locatiecode" required autofocus>
  25. </div>
  26. </div>
  27.  
  28. <div class="form-group">
  29. <div class="col-md-3">
  30. <label>Productcode</label>
  31. <input id="productcode" type="text" class="form-control" name="Productcode" required autofocus>
  32. </div>
  33. </div>
  34.  
  35. <div class="form-group">
  36. <div class="col-md-3">
  37. <label>Aantal</label>
  38. <input id="voorraad" type="text" class="form-control" name="Aantal" required autofocus>
  39. </div>
  40. </div>
  41. <div class="form-group">
  42. <div class="col-md-3">
  43. <button class="btn btn-lg btn-block" type="submit">Toevoegen</button>
  44. </div>
  45. </div>
  46. </form>
  47.  
  48.  
  49.  
  50.  
  51. <?php
  52.  
  53. if (isset($_POST['Locatiecode'])) {
  54. //echo "This var is set so I will print.";
  55.  
  56. require('connect.php');
  57.  
  58. $locatiecode = $_POST['Locatiecode'];
  59. $productcode = $_POST['Productcode'];
  60. $aantal = $_POST['Aantal'];
  61.  
  62.  
  63. $query = "SELECT Locatiecode, Productcode FROM `voorraad` WHERE Productcode='$productcode' and Locatiecode='$locatiecode'";
  64.  
  65. $result = mysqli_query($connection, $query) or die(mysqli_error($connection));
  66. $count = mysqli_num_rows($result);
  67. //
  68. if ($count == 1){
  69.  
  70. $servername = "localhost";
  71. $username = "root";
  72. $password = "";
  73. $dbname = "toolsforever";
  74. // Create connection
  75. $conn = new mysqli($servername, $username, $password, $dbname);
  76. // Check connection
  77. if ($conn->connect_error) {
  78. die("Connection failed: " . $conn->connect_error);
  79. }
  80.  
  81. $sum = 0;
  82.  
  83. $sq = "SELECT Aantal AS sum FROM voorraad WHERE Locatiecode = '$locatiecode' AND Productcode = '$productcode'";
  84.  
  85. $result = mysqli_query($mylink, $sq);
  86.  
  87. while($row = mysqli_fetch_object($result))
  88. {
  89. $GLOBALS['sum'] = $row->sum;
  90. }
  91. $GLOBALS['productaantal']= $sum + $aantal;
  92.  
  93. //echo $productaantal . "<br>";
  94.  
  95.  
  96. $sql = "UPDATE voorraad SET Aantal='$productaantal' WHERE Locatiecode= '$locatiecode' AND Productcode = '$productcode'";
  97. if ($conn->query($sql) === TRUE) {
  98. echo "Record updated successfully";
  99. } else {
  100. echo "Error updating record: " . $conn->error;
  101. }
  102.  
  103. $conn->close();
  104.  
  105.  
  106.  
  107. }else{
  108.  
  109.  
  110. $sql = "INSERT INTO voorraad (Locatiecode, Productcode, Aantal)
  111. VALUES ('$locatiecode', '$productcode', '$aantal')";
  112.  
  113. $result = mysqli_query($connection, $sql) or die(mysqli_error($connection));
  114.  
  115. $_SESSION['Locatie-toegevoegd'] = "Locatie toegevoegd!";
  116.  
  117. header("Location:voorraad.php?locatie=$locatiecode");
  118. }
  119. }
  120.  
  121. ?>
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. <?php
  131. if (count($show_voorraads)){ ?>
  132. <table class="table"> <thead>
  133. <tr>
  134. <th scope="col">Productcode</th>
  135. <th scope="col">Product</th>
  136. <th scope="col">Type</th>
  137. <th scope="col">Fabriekscode</th>
  138. <th scope="col">Inkoopprijs</th>
  139. <th scope="col">Verkoopprijs</th>
  140. </tr>
  141. </thead>
  142. <tbody>
  143. <?php foreach ($show_voorraads as $key => $list){ ?>
  144. <tr>
  145. <td><?php echo $list['Productcode']; ?></td>
  146. <td><?php echo $list['Product']; ?></td>
  147. <td><?php echo $list['Type']; ?></td>
  148. <td><?php echo $list['Fabriekscode']; ?></td>
  149. <td><?php echo $list['Inkoopprijs']; ?></td>
  150. <td><?php echo $list['Verkoopprijs']; ?></td>
  151. </tr> <?php } ?>
  152.  
  153. </table><?php }
  154. else{ ?>
  155. <p><b>Er zijn geen locatie toegevoegd!</b></p>
  156. <?php } ?>
  157.  
  158.  
  159.  
  160. <!---------------------------------------------------------------------------------------------------------------->
  161.  
  162.  
  163.  
  164. zoek.php
  165.  
  166. <?php
  167. include_once("top.php");
  168. include_once("header.php");
  169. include_once("functions.php");
  170.  
  171.  
  172. ?>
  173.  
  174. <?php
  175. ?>
  176.  
  177. <div class="row" style="margin-top: 50px;">
  178. <div class="col-6 col-md-4">
  179.  
  180. <?php include_once("sidebar.php"); ?>
  181.  
  182. </div>
  183. <div class="col-12 col-sm-6 col-md-8">
  184.  
  185. <form class="form-horizontal" role="form" action="zoek.php" method="GET">
  186. <input type="text" placeholder="zoek op Type of productnaam" name="query" />
  187. <input type="submit" value="Search" />
  188. </form>
  189.  
  190.  
  191. <?php
  192. if (isset($_GET['query'])) {
  193. $like = $_GET['query'];
  194. $show_searchs = search($like);
  195. if (count($show_searchs)){ ?>
  196. <table class="table">
  197. <thead>
  198.  
  199. <tr>
  200.  
  201. <th scope="col">Product</th>
  202. <th scope="col">Type</th>
  203. <th scope="col">Locatiecode</th>
  204. <th scope="col">Aantal op voorraad</th>
  205.  
  206. </tr>
  207. </thead>
  208. <tbody>
  209. <?php foreach ($show_searchs as $key => $list){ ?>
  210. <tr>
  211.  
  212. <td><?php echo $list['Product']; ?></td>
  213. <td><?php echo $list['Type']; ?></td>
  214. <td><?php echo $list['Locatiecode']; ?></td>
  215. <td><?php echo $list['Aantal']; ?></td>
  216.  
  217. </tr>
  218. <?php } ?>
  219. </table>
  220. <?php }
  221. else{ ?> <p><b>!</b></p>
  222.  
  223. <?php } }?>
  224.  
  225.  
  226.  
  227. </div>
  228.  
  229. </div>
  230.  
  231.  
  232.  
  233.  
  234. <?php
  235. include_once("footer.php");
  236.  
  237. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement