<!DOCTYPE html>
<html>
<head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>    
<body>
    
    <form method="post">
        <fieldset>
        <legend>Teilnehmer erfassen</legend>
        <ul>
            <li>
                <label for="tnummer">Teilnehmernummer:</label>
                <input type="text" name="tnummer" id="tnummer" value="AUTO" disabled>
            </li>
            <li>
                <label for="name">Name:</label>
                <input type="text" name="name" id="name">
            </li>
            <li>
                <label for="vname">Vorname:</label>
                <input type="text" name="vname" id="vname">
            </li>
            <li>
                <label for="plz">Postleitzahl:</label>
                <input type="text" name="plz" id="plz">
            </li>
            <li>
                <label for="ort">Ort:</label>
                <input type="text" name="ort" id="ort">
            </li>
            <li>
                <label for="strasse">Strasse</label>
                <input type="text" name="strasse" id="strasse">
            </li>
            <li>
                <label for="hausnr">Nr.:</label>
                <input type="text" name="hausnr" id="hausnr">
            </li>
            <li>
                <label for="telefon1">Telefon 1:</label>
                <input type="text" name="telefon1" id="telefon1">
            </li>
            <li>
                <label for="telefon2">Telefon2</label>
                <input type="text" name="telefon2" id="telefon2">
            </li>
            <li>
                <label for="email">E-Mail:</label>
                <input type="text" name="email" id="email">
            </li>
        </ul>
        <p>
            <input type="submit" value="Teilnehmer Speichern">
        </p>
        </fieldset>
    </form>
    <?php

include("list.php");

if(isset($_POST["name"])){
    $tnummer = NULL;
    $name = $_POST["name"];
    $vname = $_POST["vname"];
    $plz = $_POST["plz"];
    $ort = $_POST["ort"];
    $strasse = $_POST["strasse"];
    $hausnr = $_POST["hausnr"];
    $telefon1 = $_POST["telefon1"];
    $telefon2 = $_POST["telefon2"];
    $email = $_POST["email"];


    try {
        $pdo = new PDO ("mysql:dbname=$dbname;host=$dbhost;charset=utf8", $dbuser, $dbpw);
    }
    catch (PDOException $e) {
        die ($e->getmessage());
    }
}

$sql = "INSERT INTO teilnehmer ( tnummer, name, vname, plz, ort, strasse, hausnr, telefon1, telefon2, email) VALUES ( :tnummer, :name, :vname, :plz, :ort, :strasse, :hausnr, :telefon1, :telefon2, :email)";

if ($stmt = $pdo->prepare($sql)) {
 
/* Altenative zu bindParam: */

$param = array(
    ':tnummer' => $tnummer,
    ':name' => $name,
    ':vname' => $vname,
    ':plz' => $plz,
    ':ort' => $ort,
    ':strasse' => $strasse,
    ':hausnr' => $hausnr,
    ':telefon1' => $telefon1,
    ':telefon2' => $telefon2,
    ':email' => $email
);
 
/*  $stmt->bindParam(':tnummer' ,$tnummer);
    $stmt->bindParam(':name' ,$name);
    $stmt->bindParam(':vname' ,$vname);
    $stmt->bindParam(':plz' ,$plz);
    $stmt->bindParam(':ort' ,$ort);
    $stmt->bindParam(':strasse' ,$strasse);
    $stmt->bindParam(':hausnr' ,$hausnr);
    $stmt->bindParam(':telefon1' ,$telefon1);
    $stmt->bindParam(':telefon2' ,$telefon2);
    $stmt->bindParam(':email' ,$email);

*/

    if ($stmt->execute($param)) {
        echo "<h2>Datensatz erfolgreich gespeichert! </h2>\n";
    }
    else {
        echo "<h2>Fehler beim Speichern!</h2>\n";
    }
}
?>
    </body>
</html>

