Advertisement
Guest User

product-table.php

a guest
Apr 3rd, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. <?php
  2. include('dbconnect.php');
  3. //hier word de tabel met alle producten gemaakt
  4. $sql = "SELECT * FROM product";
  5. $result = $db->query($sql);
  6.  
  7. if ($result->num_rows > 0) {
  8. echo "<p> <h2>Producten:</h2>";
  9. //tabel word gemaakt door een while loop en daarin de sql resultaten
  10. echo "<table><tr><th>Productcode </th><th>Product </th><th>Type </th><th>Fabriekscode </th><th>Inkoopprijs </th><th>Verkoopprijs </th></tr>";
  11. while($row = $result->fetch_assoc()) {
  12. echo "<tr><td>".$row["Productcode"]."</td><td>".$row["Product"]."</td><td>".$row["Type"]."</td><td>".$row["Fabriekscode"]."</td><td>&euro; ".$row["Inkoopprijs"]."</td><td>&euro; ".$row["Verkoopprijs"]."</td></tr>";
  13. }
  14. echo "</table>";
  15. }
  16. //hier wordt de voorrad van de producten per locatie getoond
  17. echo "<p> <h2>Voorraad producten per locatie:</h2>";
  18. if (isset ($_POST['locatiecode'])) {
  19. $locatiecode = ($_POST['locatiecode']);
  20.  
  21. $sql2 = "SELECT * FROM voorraad WHERE locatiecode='$locatiecode'";
  22. $result2 = $db->query($sql2);
  23.  
  24. if ($result2->num_rows > 0) {
  25. //tabel word gemaakt door een while loop en daarin de sql resultaten
  26. echo "<table><tr><th>Locatie </th><th>Productcode </th><th>Aantal </th></tr>";
  27. while($row = $result2->fetch_assoc()) {
  28. echo "<tr><td>".$row["Locatiecode"]."</td><td>".$row["Productcode"]."</td><td>".$row["Aantal"]."</td></tr>";
  29. }
  30. echo "</table>";
  31. }
  32. }
  33. if (isset ($_POST['productcode2'], $_POST['locatiecode2'], $_POST['aantal2'])){
  34.  
  35. $productcode2 = ($_POST["productcode2"]);
  36. $locatiecode2 = ($_POST["locatiecode2"]);
  37. $aantal2 = ($_POST['aantal2']);
  38. //updaten van de vooraad word hier gedaan met een update en set command
  39.  
  40. $sql2 = "UPDATE voorraad SET aantal = aantal + '$aantal2' WHERE productcode = '$productcode2' AND locatiecode = '$locatiecode2'";
  41.  
  42. if (mysqli_query($db, $sql2)) {
  43. echo "Voorraad toegevoegd";
  44. } else {
  45. echo "Fout bij het toevoegen van voorraad!";
  46. }
  47. }
  48.  
  49. if (isset ($_POST['locatiecode'])) {
  50. $locatiecode = ($_POST['locatiecode']);
  51.  
  52. $sql3 = "SELECT * FROM voorraad WHERE locatiecode='$locatiecode'";
  53. $result3 = $db->query($sql3);
  54.  
  55. if ($result2->num_rows > 0) {
  56. //tabel word gemaakt door een while loop en daarin de sql resultaten
  57. while($row = $result2->fetch_assoc()) {
  58. }
  59. echo "</table>";
  60. }
  61. }
  62.  
  63. // php code to Insert data into mysql database from input text
  64. if(isset($_POST['insert']))
  65. {
  66. $hostname = "localhost";
  67. $username = "root";
  68. $password = "";
  69. $databaseName = "toolsforever";
  70.  
  71. // get values form input text and number
  72.  
  73. $productcode3 = $_POST['productcode3'];
  74. $locatiecode3 = $_POST['locatiecode3'];
  75. $aantal3 = $_POST['aantal3'];
  76.  
  77. // connect to mysql database using mysqli
  78.  
  79. $connect = mysqli_connect($hostname, $username, $password, $databaseName);
  80.  
  81. // mysql query to insert data
  82.  
  83. $query = "INSERT INTO `voorraad`(`Productcode`, `Locatiecode`, `Aantal`) VALUES ('$productcode3','$locatiecode3','$aantal3')";
  84.  
  85. $result = mysqli_query($connect,$query);
  86.  
  87. // check if mysql query successful
  88.  
  89. if($result)
  90. {
  91. echo 'Data Inserted';
  92. }
  93.  
  94. else{
  95. echo 'Data Not Inserted';
  96. }
  97.  
  98. mysqli_free_result($result);
  99. mysqli_close($connect);
  100. }
  101.  
  102.  
  103.  
  104. /*if (isset ($_POST['productcode3'], $_POST['locatiecode3'], $_POST['aantal3'])){
  105.  
  106. $productcode3 = ($_POST["productcode3"]);
  107. $locatiecode3 = ($_POST["locatiecode3"]);
  108. $aantal3 = ($_POST['aantal3']);
  109. //updaten van de vooraad word hier gedaan met een update en set command
  110.  
  111. $sql3 = "INSERT INTO voorraad (Productcode, Locatiecode, Aantal)
  112. VALUES('$productcode3', '$locatiecode3', '$aantal3')";
  113.  
  114. if (mysqli_query($db, $sql3)) {
  115. echo "Voorraad toegevoegd";
  116. } else {
  117. echo "Fout bij het toevoegen van voorraad!";
  118. }
  119. }*/
  120.  
  121. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement