<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Gästebuch</title> <style type="text/css"> body {width:500px; margin:0px auto; font-family:Verdana, Tahoma, Arial, sans-serif; font-size:0.8em; background-color:#ffc;} h1 {border:1px dotted red; background-color: #ffffff;} h2 {background-color:black; color:white; margin-bottom:0px; padding:6px;} p.form {border:1px solid black; margin-top:0px; padding:6px;} label {display:inline-block; width:120px;} /* Hier wird das Formular gestylt */ form {background-color:#b5b5b5; padding:10px; border:2px solid blue;} input, textarea {width:300px; min-width:300px; max-width:300px;} textarea {min-height:110px; max-height:120px;} </style> </head> <body> <h1>Gästebuch</h1> <?php // Verbindung herstellen: $myConnection = mysql_connect("localhost","root",""); //Datenbank auswählen: mysql_select_db("gaestebuch"); if (isset($_POST['absenden'])) { // erst diesen neuen Eintrag speichern: mysql_query("INSERT INTO gaestebuch (Name,Mail,Text) VALUES('" . $_POST['Name'] . "','". $_POST['Mail'] ."','" . str_replace( "\n", "<br>", $_POST['Text'] ) . "');"); } // SQL-Befehl absetzen: $myResult = mysql_query("SELECT * FROM gaestebuch"); // Alle Datensätze nacheinander behandeln: while ($myData = mysql_fetch_assoc($myResult)) { echo "<h2>" . $myData['Name'] . " schrieb am " . $myData['Zeit'] . "</h2>\n"; echo ' <p class="form">' . $myData['Text'] . "</p>\n"; } // muss nicht sein, ist aber höflich: mysql_close($myConnection); ?> <form method="post" action="mysql1.php"> <p>Erstellen Sie einen neuen Eintrag:</p> <label for="Name">Ihr Name:</label> <input type="text" id="Name" name="Name" required="required"><br> <label for="Mail">Ihre Mailadresse:</label> <input type="text" id="Mail" name="Mail" required="required"><br> <label for="Text">Ihr Eintrag:</label> <textarea id="Text" name="Text" required="required"></textarea><br> <label></label> <input type="submit" value="jetzt eintragen" name="absenden"><br> </form> </body> </html>