Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- .error {color: #FF0000;}
- </style>
- </head>
- <body>
- <?php
- $leerlingnaamErr = $vakErr = $cijferErr = "";
- $leerlingnaam = $vak = $cijfer = "";
- $ok = true;
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if (empty($_POST["leerlingnaam"])) {
- $leerlingnaamErr = "Leerlingnaam is verplicht!";
- $ok = false;
- }else {
- $leerlingnaam = test_input ($_POST["leerlingnaam"]);
- }
- if (empty($_POST["cijfer"])) {
- $cijferErr = "cijfer is verplicht!";
- }else {
- $cijfer = test_input($_POST["cijfer"]);
- }
- if (empty($_POST["vak"])) {
- $vakErr = "vak is verplicht!";
- }else {
- $vak = test_input($_POST["vak"]);
- }
- }
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <h2>Regristratie van uw info</h2>
- <p><span class = "error">* verplicht veld.</span></p>
- <form method = "POST" action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- <table>
- <tr>
- <td maxlength="10">leerlingnaam:</td>
- <td><input type = "text" name = "leerlingnaam" required maxlength="30" value="<?php echo $leerlingnaam;?>">
- <span class = "error">* <?php echo $leerlingnaamErr;?></span>
- </td>
- </tr>
- <tr>
- <td>cijfer:</td>
- <td> <input type = "number" name = "cijfer" required maxlength="1" value="<?php echo $cijfer;?>">
- <span class = "error"><?php echo $cijferErr;?></span>
- </td>
- </tr>
- <tr>
- <td>vak:</td>
- <td> <input type = "text" name = "vak" required maxlength="10" value="<?php echo $vak;?>">
- <span class = "error">* <?php echo $vakErr;?></span>
- </td>
- </tr>
- <tr>
- <td>
- <input type = "submit" name = "submit" value = "Submit">
- </td>
- </tr>
- </table>
- </form>
- <?php
- $spatie = " - ";
- if ($ok) {
- echo "<h2>Zijn dit je gegevens? :</h2>";
- echo ("<p>Je leerlingnaam is $leerlingnaam</p>");
- echo ("<p> Je cijfer is $cijfer</p>");
- echo ("<p>Je vak is $vak </p>");
- }
- ?><br><br><br>
- <?php
- $servername = "localhost";
- $username = "raifex";
- $password = "";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=cijferlijst", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- echo "Connected successfully";
- }
- catch(PDOException $e)
- {
- echo "Connection failed: " . $e->getMessage();
- }
- $sql = "Insert into cijfer
- (vak, leerlingnaam, cijfer)
- VALUES ('$vak','$leerlingnaam','$cijfer')";
- $conn->exec($sql);
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement