Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['senden'])) {
- if(isset($_POST['firstname'])) {
- $fname = $_POST['firstname'];
- }
- if(isset($_POST['lastname'])) {
- $lname = $_POST['lastname'];
- }
- if(isset($_POST['class'])) {
- $class = $_POST['class'];
- }
- if(isset($_POST['age'])) {
- $age = $_POST['age'];
- }
- }
- else {
- $sql ="INSERT INTO Personen VALUES (\"".
- $fname."\",\"".$lname."\",\"".$class."\",".$_POST['age'].
- ");";
- if(mysql_query($conn, $sql) === TRUE ) {
- echo ("<h2>Eintrag erfolgreich</h2>");
- }
- }
- $server = "localhost";
- $user = "root";
- $pass = "";
- $database = "schule";
- $conn = new mysqli($server, $user, $pass, $database);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- /* echo "Connection succesfully"; -- nur während der testpahse */
- $sql = "SELECT * FROM Personen";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- echo "Firstname: " . $row["Firstname"]. " - Lastname: " . $row["Lastname"]. " - Class: " . $row["Class"]. " " . $row["Age"]. "</br>"; /* .$row['Firstname'] . */
- }
- } else {
- echo "0 results";
- }
- <html>
- <body>
- <form action="index.php" method="post"/>
- <table>
- <td>Vorname:</td><td><input type ="text" name="firstname" size="40" maxlength="40" />
- <td>Nachname:</td><td><input type ="text" name="lastname" size="40" maxlength="40" />
- <td>Klasse:</td><td><input type ="text" name="class" size="40" maxlength="40" />
- <td>Alter:</td><td><input type ="text" name="age" size="40" maxlength="40" />
- </table>
- <button name="senden" type="submt"> Eingabe absenden </button>
- </form>
- </body>
- </html>
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement