Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. <?php
  2. //require "Mollie/API/Autoloader.php";
  3.  
  4.  
  5. function test_input($data) {
  6. $data = htmlentities($data);
  7. return $data;
  8. }
  9.  
  10. function getLastGroupId($conn){
  11. $lastGroupId = 1;
  12. /*
  13. $sql = "SELECT * FROM `groepen` ORDER BY `Id` DESC LIMIT 1;";
  14. $stmt = mysqli_query($conn, $sql) or die(mysqli_error());
  15. if (mysqli_num_rows($stmt) == 1) {
  16. $row = mysqli_fetch_assoc($stmt);
  17. $id = $row['Id'];
  18. $lastGroupId = $row['groepId'];
  19. $lastGroupId = $lastGroupId + 1;
  20. }
  21. */
  22.  
  23. return $lastGroupId;
  24. }
  25.  
  26. //need localhost to test
  27.  
  28. $servername = "galabalmarine.be.mysql:3306";
  29. $username = "galabalmarine_be";
  30. $password = "**********";
  31. $dbname = "galabalmarine_be";
  32.  
  33.  
  34. //local connection
  35.  
  36. $servername = "localhost:3306";
  37. $username = "root";
  38. $password = "root";
  39. $dbname = "galabalmarine";
  40.  
  41. // Create connection
  42.  
  43. $conn = mysqli_connect($servername, $username, $password, $dbname);
  44.  
  45. // Check connection
  46. if (!$conn) {
  47. die("Connection failed: " . mysqli_connect_error());
  48. }else{
  49. echo "<p>connection succestfull</p>";
  50. }
  51.  
  52.  
  53. if (isset($_POST['submit'])) {
  54. echo "hello!";
  55. //regular form
  56.  
  57. $naam=test_input($_POST['naam']);
  58. echo "naam: ".$naam;
  59. $voornaam=test_input($_POST['voornaam']);
  60. $straat=test_input($_POST['straat']);
  61. $huisnummer=test_input($_POST['huisnummer']);
  62. $stad=test_input($_POST['stad']);
  63. $telefoonnummer=test_input($_POST['tel']);
  64. $titel=test_input($_POST['titel']);
  65. $parkeerplaats = test_input($_POST['parkeer']);
  66. $militaireCategorie=test_input($_POST['categorie']);
  67. $militaireGraad=test_input($_POST["graad"]);
  68. $partner=test_input($_POST['partner']);
  69. if($partner == "on"){
  70. $partner = "ja";
  71. }else{
  72. $partner = "nee";
  73. }
  74. $dinner=test_input($_POST['dinner']);
  75. if($dinner == "on"){
  76. $dinner = "ja";
  77. }else{
  78. $dinner = "nee";
  79. }
  80. $gift=test_input($_POST['gift']);
  81. $extrapers=test_input($_POST['extrapersonen']);
  82. $email=test_input($_POST['email']);
  83. $firma=test_input($_POST["firma"]);
  84. $opmerking=test_input($_POST["extra"]);
  85. $lastGroupId = "none";
  86.  
  87. //check if extrapersonen
  88. if($extrapers > 0){
  89. //get last groupid
  90. $lastGroupId = getLastGroupId($conn);
  91. echo "<p>last group id: ".$lastGroupId."</p>";
  92. //inserting extramembers
  93. for($i=1;$i<=$extrapers;$i++){
  94.  
  95. $extradinner = test_input($_POST["extradinner" . $i]);
  96. if($extradinner == "on"){
  97. $extradinner = "ja";
  98. }else{
  99. $extradinner = "nee";
  100. }
  101. echo "<p>extradinner: ".$extradinner;
  102. $extranaam = test_input($_POST["extranaam" . $i]);
  103. echo "<p>extranaam: ".$extranaam;
  104. $extravoornaam = test_input($_POST["extravoornaam" . $i]);
  105. echo "<p>extravoornaam: ".$extravoornaam;
  106. $extracategorie = test_input($_POST["extracategorie" . $i]);
  107. echo "<p>extracategorie: ".$extracategorie;
  108. //need to be changed into $naam."_".$voornaam -- nu enkel als voorbeeld
  109. $naamvoornaam = "voorbeeldnaam";
  110.  
  111. //whats wrong??
  112.  
  113. $stmt = $conn->prepare("INSERT INTO `groepen`(groepId`, `naam`, `voornaam`, `militaire-categorie`, `dinner`, `naam_voornaam_inschrijver`) VALUES (?,?,?,?,?,?)");
  114. $stmt->bind_param("isssss", $lastGroupId ,$extranaam ,$extravoornaam, $extracategorie,$extradinner, $naamvoornaam );
  115. if ($stmt->execute() === TRUE) {
  116. //echo "New record" + $counter + " created successfully";
  117. echo'<script>alert("succes: ' . $counter . '")</script>';
  118. } else {
  119. //echo "Error: " . $sql . "<br>" . $stmt->error;
  120. echo'<script>alert("nosucces: ' . $counter . '")</script>';
  121. }
  122. }
  123. }
  124. }
  125.  
  126.  
  127.  
  128. ?>
  129.  
  130. <p>trying to do some shit...</p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement