Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['senden'])) {
  3. if(isset($_POST['firstname'])) {
  4. $fname = $_POST['firstname'];
  5. }
  6. if(isset($_POST['lastname'])) {
  7. $lname = $_POST['lastname'];
  8. }
  9. if(isset($_POST['class'])) {
  10. $class = $_POST['class'];
  11. }
  12. if(isset($_POST['age'])) {
  13. $age = $_POST['age'];
  14. }
  15.  
  16. }
  17.  
  18. else {
  19. $sql ="INSERT INTO Personen VALUES (\"".
  20. $fname."\",\"".$lname."\",\"".$class."\",".$_POST['age'].
  21. ");";
  22.  
  23. if(mysql_query($conn, $sql) === TRUE ) {
  24. echo ("<h2>Eintrag erfolgreich</h2>");
  25. }
  26. }
  27.  
  28. $server = "localhost";
  29. $user = "root";
  30. $pass = "";
  31. $database = "schule";
  32.  
  33. $conn = new mysqli($server, $user, $pass, $database);
  34.  
  35. if ($conn->connect_error) {
  36. die("Connection failed: " . $conn->connect_error);
  37. }
  38.  
  39. /* echo "Connection succesfully"; -- nur während der testpahse */
  40.  
  41. $sql = "SELECT * FROM Personen";
  42. $result = $conn->query($sql);
  43.  
  44. if ($result->num_rows > 0) {
  45. // output data of each row
  46. while($row = $result->fetch_assoc()) {
  47. echo "Firstname: " . $row["Firstname"]. " - Lastname: " . $row["Lastname"]. " - Class: " . $row["Class"]. " " . $row["Age"]. "</br>"; /* .$row['Firstname'] . */
  48. }
  49. } else {
  50. echo "0 results";
  51. }
  52.  
  53. <html>
  54. <body>
  55.  
  56. <form action="index.php" method="post"/>
  57.  
  58. <table>
  59.  
  60. <td>Vorname:</td><td><input type ="text" name="firstname" size="40" maxlength="40" />
  61. <td>Nachname:</td><td><input type ="text" name="lastname" size="40" maxlength="40" />
  62. <td>Klasse:</td><td><input type ="text" name="class" size="40" maxlength="40" />
  63. <td>Alter:</td><td><input type ="text" name="age" size="40" maxlength="40" />
  64.  
  65.  
  66.  
  67.  
  68. </table>
  69.  
  70. <button name="senden" type="submt"> Eingabe absenden </button>
  71.  
  72. </form>
  73. </body>
  74. </html>
  75.  
  76. $conn->close();
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement