Advertisement
Guest User

Untitled

a guest
Nov 28th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. table,tr,td,th {
  6. border: 1px solid black;
  7. border-collapse: collapse;
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <form method= "POST">
  13. <?php
  14.  
  15. $servername = "localhost";
  16. $username = "paer12";
  17. $password = "Paulaldabagh12";
  18.  
  19. require "testinput.php";
  20.  
  21. try {
  22. $conn = new PDO("mysql:host=$servername;dbname=php2", $username, $password);
  23.  
  24. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  25. echo "";
  26. }
  27. catch(PDOException $e)
  28. {
  29. echo "Connection failed: " . $e->getMessage();
  30. }
  31.  
  32.  
  33. $sql = "select * from vak";
  34. $result= $conn->query($sql);
  35.  
  36. echo '<select name="vak" ();">';
  37. echo '<option value=""></option>';
  38.  
  39. foreach ($result as $row) {
  40. echo '<option value="'.$row['id'].'">'.$row['titel'].'</option>';
  41. }
  42. echo "</select>";
  43. ?>
  44. <form method = "POST" action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  45. <table>
  46. <th>leerlingnaam</th><th>cijfer</th>
  47. <tr>
  48. <td>
  49. <?php
  50. $sql = "select * from Leerling";
  51. $result= $conn->query($sql);
  52.  
  53. echo '<select name="leerlingnaam1"();">';
  54. echo '<option value=""></option>';
  55.  
  56. foreach ($result as $row) {
  57. echo '<option value="'.$row['id'].'">'.$row['voornaam'].'</option>';
  58. }
  59. echo "</select>";
  60. ?></td>
  61. <td><input class="short-input" type="text" name="cijfer1"/></td>
  62. </tr>
  63. <tr>
  64. <td> <?php
  65. $sql = "select * from Leerling";
  66. $result= $conn->query($sql);
  67.  
  68. echo '<select name="leerlingnaam2"();">';
  69. echo '<option value=""></option>';
  70.  
  71. foreach ($result as $row) {
  72. echo '<option value="'.$row['id'].'">'.$row['voornaam'].'</option>';
  73. }
  74. echo "</select>";
  75. ?></td>
  76. <td><input class="short-input" type="text" name="cijfer2"/></td>
  77. </tr>
  78. <tr>
  79. <td> <?php
  80. $sql = "select * from Leerling";
  81. $result= $conn->query($sql);
  82.  
  83. echo '<select name="leerlingnaam3"();">';
  84. echo '<option value=""></option>';
  85.  
  86. foreach ($result as $row) {
  87. echo '<option value="'.$row['id'].'">'.$row['voornaam'].'</option>';
  88. }
  89. echo "</select>";
  90. ?></td>
  91. <td><input class="short-input" type="text" name="cijfer3"/></td>
  92. </tr>
  93. <tr>
  94. <td> <?php
  95. $sql = "select * from Leerling";
  96. $result= $conn->query($sql);
  97.  
  98. echo '<select name="leerlingnaam4"();">';
  99. echo '<option value=""></option>';
  100.  
  101. foreach ($result as $row) {
  102. echo '<option value="'.$row['id'].'">'.$row['voornaam'].'</option>';
  103. }
  104. echo "</select>";
  105. ?>
  106. </td>
  107. <td><input class="short-input" type="text" name="cijfer4"/></td>
  108. </tr>
  109.  
  110. </table>
  111. <br>
  112. <input type = "submit" name = "Versturen" value = "Versturen">
  113. </form>
  114.  
  115.  
  116.  
  117. <?php
  118.  
  119.  
  120. if (isset($_POST['Versturen'])) {
  121. $stmt = $conn->prepare("INSERT INTO Cijfer2
  122. (leerling_id, vak_id, cijfer) VALUES
  123. (:leerlingnaam, :vak, :cijfer)");
  124.  
  125. $stmt->bindParam(':leerlingnaam', $leerlingnaam);
  126. $stmt->bindParam(':vak', $vak);
  127. $stmt->bindParam(':cijfer', $cijfer);
  128.  
  129. $vak= test_input($_POST["vak"]);
  130.  
  131. for ($i=1;$i<=4;$i++) {
  132. $leerlingnaam = test_input($_POST["leerlingnaam".$i]);
  133. $cijfer = test_input($_POST["cijfer".$i]);
  134.  
  135. if ($leerlingnaam!= "" and $cijfer!="") {
  136. $stmt->execute();
  137. }
  138. }
  139. }
  140.  
  141. $conn = null;
  142.  
  143. ?>
  144.  
  145. </table>
  146. </body>
  147. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement