Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <style>
  6. .error {color: #FF0000;}
  7. </style>
  8. </head>
  9.  
  10. <body>
  11. <?php
  12. $leerlingnaamErr = $vakErr = $cijferErr = "";
  13. $leerlingnaam = $vak = $cijfer = "";
  14. $ok = true;
  15. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  16. if (empty($_POST["leerlingnaam"])) {
  17. $leerlingnaamErr = "Leerlingnaam is verplicht!";
  18. $ok = false;
  19. }else {
  20. $leerlingnaam = test_input ($_POST["leerlingnaam"]);
  21. }
  22.  
  23. if (empty($_POST["cijfer"])) {
  24. $cijferErr = "cijfer is verplicht!";
  25. }else {
  26. $cijfer = test_input($_POST["cijfer"]);
  27.  
  28. }
  29.  
  30. if (empty($_POST["vak"])) {
  31. $vakErr = "vak is verplicht!";
  32. }else {
  33. $vak = test_input($_POST["vak"]);
  34. }
  35.  
  36. }
  37. function test_input($data) {
  38. $data = trim($data);
  39. $data = stripslashes($data);
  40. $data = htmlspecialchars($data);
  41. return $data;
  42. }
  43. ?>
  44.  
  45. <h2>Regristratie van uw info</h2>
  46.  
  47. <p><span class = "error">* verplicht veld.</span></p>
  48.  
  49. <form method = "POST" action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  50. <table>
  51. <tr>
  52. <td maxlength="10">leerlingnaam:</td>
  53. <td><input type = "text" name = "leerlingnaam" required maxlength="30" value="<?php echo $leerlingnaam;?>">
  54. <span class = "error">* <?php echo $leerlingnaamErr;?></span>
  55. </td>
  56. </tr>
  57. <tr>
  58. <td>cijfer:</td>
  59. <td> <input type = "number" name = "cijfer" required maxlength="1" value="<?php echo $cijfer;?>">
  60. <span class = "error"><?php echo $cijferErr;?></span>
  61. </td>
  62. </tr>
  63.  
  64. <tr>
  65. <td>vak:</td>
  66. <td> <input type = "text" name = "vak" required maxlength="10" value="<?php echo $vak;?>">
  67. <span class = "error">* <?php echo $vakErr;?></span>
  68. </td>
  69. </tr>
  70. <tr>
  71. <td>
  72. <input type = "submit" name = "submit" value = "Submit">
  73. </td>
  74. </tr>
  75.  
  76. </table>
  77.  
  78. </form>
  79.  
  80. <?php
  81. $spatie = " - ";
  82. if ($ok) {
  83. echo "<h2>Zijn dit je gegevens? :</h2>";
  84. echo ("<p>Je leerlingnaam is $leerlingnaam</p>");
  85. echo ("<p> Je cijfer is $cijfer</p>");
  86. echo ("<p>Je vak is $vak </p>");
  87. }
  88.  
  89. ?><br><br><br>
  90. <?php
  91. $servername = "localhost";
  92. $username = "raifex";
  93. $password = "";
  94.  
  95. try {
  96. $conn = new PDO("mysql:host=$servername;dbname=cijferlijst", $username, $password);
  97. // set the PDO error mode to exception
  98. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  99. echo "Connected successfully";
  100. }
  101. catch(PDOException $e)
  102. {
  103. echo "Connection failed: " . $e->getMessage();
  104. }
  105. $sql = "Insert into cijfer
  106. (vak, leerlingnaam, cijfer)
  107. VALUES ('$vak','$leerlingnaam','$cijfer')";
  108.  
  109. $conn->exec($sql);
  110. ?>
  111. </body>
  112. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement