Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //require "Mollie/API/Autoloader.php";
- function test_input($data) {
- $data = htmlentities($data);
- return $data;
- }
- function getLastGroupId($conn){
- $lastGroupId = 1;
- /*
- $sql = "SELECT * FROM `groepen` ORDER BY `Id` DESC LIMIT 1;";
- $stmt = mysqli_query($conn, $sql) or die(mysqli_error());
- if (mysqli_num_rows($stmt) == 1) {
- $row = mysqli_fetch_assoc($stmt);
- $id = $row['Id'];
- $lastGroupId = $row['groepId'];
- $lastGroupId = $lastGroupId + 1;
- }
- */
- return $lastGroupId;
- }
- //need localhost to test
- $servername = "galabalmarine.be.mysql:3306";
- $username = "galabalmarine_be";
- $password = "**********";
- $dbname = "galabalmarine_be";
- //local connection
- $servername = "localhost:3306";
- $username = "root";
- $password = "root";
- $dbname = "galabalmarine";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }else{
- echo "<p>connection succestfull</p>";
- }
- if (isset($_POST['submit'])) {
- echo "hello!";
- //regular form
- $naam=test_input($_POST['naam']);
- echo "naam: ".$naam;
- $voornaam=test_input($_POST['voornaam']);
- $straat=test_input($_POST['straat']);
- $huisnummer=test_input($_POST['huisnummer']);
- $stad=test_input($_POST['stad']);
- $telefoonnummer=test_input($_POST['tel']);
- $titel=test_input($_POST['titel']);
- $parkeerplaats = test_input($_POST['parkeer']);
- $militaireCategorie=test_input($_POST['categorie']);
- $militaireGraad=test_input($_POST["graad"]);
- $partner=test_input($_POST['partner']);
- if($partner == "on"){
- $partner = "ja";
- }else{
- $partner = "nee";
- }
- $dinner=test_input($_POST['dinner']);
- if($dinner == "on"){
- $dinner = "ja";
- }else{
- $dinner = "nee";
- }
- $gift=test_input($_POST['gift']);
- $extrapers=test_input($_POST['extrapersonen']);
- $email=test_input($_POST['email']);
- $firma=test_input($_POST["firma"]);
- $opmerking=test_input($_POST["extra"]);
- $lastGroupId = "none";
- //check if extrapersonen
- if($extrapers > 0){
- //get last groupid
- $lastGroupId = getLastGroupId($conn);
- echo "<p>last group id: ".$lastGroupId."</p>";
- //inserting extramembers
- for($i=1;$i<=$extrapers;$i++){
- $extradinner = test_input($_POST["extradinner" . $i]);
- if($extradinner == "on"){
- $extradinner = "ja";
- }else{
- $extradinner = "nee";
- }
- echo "<p>extradinner: ".$extradinner;
- $extranaam = test_input($_POST["extranaam" . $i]);
- echo "<p>extranaam: ".$extranaam;
- $extravoornaam = test_input($_POST["extravoornaam" . $i]);
- echo "<p>extravoornaam: ".$extravoornaam;
- $extracategorie = test_input($_POST["extracategorie" . $i]);
- echo "<p>extracategorie: ".$extracategorie;
- //need to be changed into $naam."_".$voornaam -- nu enkel als voorbeeld
- $naamvoornaam = "voorbeeldnaam";
- //whats wrong??
- $stmt = $conn->prepare("INSERT INTO `groepen`(groepId`, `naam`, `voornaam`, `militaire-categorie`, `dinner`, `naam_voornaam_inschrijver`) VALUES (?,?,?,?,?,?)");
- $stmt->bind_param("isssss", $lastGroupId ,$extranaam ,$extravoornaam, $extracategorie,$extradinner, $naamvoornaam );
- if ($stmt->execute() === TRUE) {
- //echo "New record" + $counter + " created successfully";
- echo'<script>alert("succes: ' . $counter . '")</script>';
- } else {
- //echo "Error: " . $sql . "<br>" . $stmt->error;
- echo'<script>alert("nosucces: ' . $counter . '")</script>';
- }
- }
- }
- }
- ?>
- <p>trying to do some shit...</p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement