Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- table,tr,td,th {
- border: 1px solid black;
- border-collapse: collapse;
- }
- </style>
- </head>
- <body>
- <form method= "POST">
- <?php
- $servername = "localhost";
- $username = "paer12";
- $password = "Paulaldabagh12";
- require "testinput.php";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=php2", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- echo "";
- }
- catch(PDOException $e)
- {
- echo "Connection failed: " . $e->getMessage();
- }
- $sql = "select * from vak";
- $result= $conn->query($sql);
- echo '<select name="vak" ();">';
- echo '<option value=""></option>';
- foreach ($result as $row) {
- echo '<option value="'.$row['id'].'">'.$row['titel'].'</option>';
- }
- echo "</select>";
- ?>
- <form method = "POST" action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- <table>
- <th>leerlingnaam</th><th>cijfer</th>
- <tr>
- <td>
- <?php
- $sql = "select * from Leerling";
- $result= $conn->query($sql);
- echo '<select name="leerlingnaam1"();">';
- echo '<option value=""></option>';
- foreach ($result as $row) {
- echo '<option value="'.$row['id'].'">'.$row['voornaam'].'</option>';
- }
- echo "</select>";
- ?></td>
- <td><input class="short-input" type="text" name="cijfer1"/></td>
- </tr>
- <tr>
- <td> <?php
- $sql = "select * from Leerling";
- $result= $conn->query($sql);
- echo '<select name="leerlingnaam2"();">';
- echo '<option value=""></option>';
- foreach ($result as $row) {
- echo '<option value="'.$row['id'].'">'.$row['voornaam'].'</option>';
- }
- echo "</select>";
- ?></td>
- <td><input class="short-input" type="text" name="cijfer2"/></td>
- </tr>
- <tr>
- <td> <?php
- $sql = "select * from Leerling";
- $result= $conn->query($sql);
- echo '<select name="leerlingnaam3"();">';
- echo '<option value=""></option>';
- foreach ($result as $row) {
- echo '<option value="'.$row['id'].'">'.$row['voornaam'].'</option>';
- }
- echo "</select>";
- ?></td>
- <td><input class="short-input" type="text" name="cijfer3"/></td>
- </tr>
- <tr>
- <td> <?php
- $sql = "select * from Leerling";
- $result= $conn->query($sql);
- echo '<select name="leerlingnaam4"();">';
- echo '<option value=""></option>';
- foreach ($result as $row) {
- echo '<option value="'.$row['id'].'">'.$row['voornaam'].'</option>';
- }
- echo "</select>";
- ?>
- </td>
- <td><input class="short-input" type="text" name="cijfer4"/></td>
- </tr>
- </table>
- <br>
- <input type = "submit" name = "Versturen" value = "Versturen">
- </form>
- <?php
- if (isset($_POST['Versturen'])) {
- $stmt = $conn->prepare("INSERT INTO Cijfer2
- (leerling_id, vak_id, cijfer) VALUES
- (:leerlingnaam, :vak, :cijfer)");
- $stmt->bindParam(':leerlingnaam', $leerlingnaam);
- $stmt->bindParam(':vak', $vak);
- $stmt->bindParam(':cijfer', $cijfer);
- $vak= test_input($_POST["vak"]);
- for ($i=1;$i<=4;$i++) {
- $leerlingnaam = test_input($_POST["leerlingnaam".$i]);
- $cijfer = test_input($_POST["cijfer".$i]);
- if ($leerlingnaam!= "" and $cijfer!="") {
- $stmt->execute();
- }
- }
- }
- $conn = null;
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement