Jump to content

Chronos313

New Members
  • Posts

    1
  • Joined

  • Last visited

Chronos313's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello together, I'm still relatively new with PHP and I'm encountering an error with the error code (Warning: Undefined array key "title" in I:\xampp\htdocs\test\Datenspeichern.php on line 13 to 17.). Normally I wanted that when I enter the data in the fields from the CD_Website page, that it is inserted in my created database and displayed in the table on the page. Does anyone know where my error is? Thanks a lot main Code= <!doctype html> <html> <head> <meta charset="utf-8"> <title>Unbenanntes Dokument</title> <style type="text/css"> table { border-collaps: collapse; width: 100%; font-family: serif; font-size: 35px; text-align: center; } td { font-size: 25px; text-align: center; font-family: serif; } </style> </head> <body> <table> <tr> <th>CD-Titel</th> <th>Artist</th> <th>Songtitel</th> <th>Musiklänge</th> <th>Lied Nummer</th> </tr> <?php $host = "localhost"; $user = "root"; $password = ""; $db_name = "cdaufgabe"; $con = mysqli_connect($host, $user, $password, $db_name); if(mysqli_connect_error()) { die("Verbindungsabbruch mit der Datenbank: ". mysqli_connect_error()); }; $check = "SELECT * FROM `cd-titel`"; $result = mysqli_query($con, $check); if ($result > null) { while ($row = $result->fetch_assoc()){ echo "<tr><td>" . $row['CD-Titel'] . "</td> <td>" . $row['Artist'] . "</td> <td>" . $row['Songtitel'] . "</td> <td>" . $row['Musiklänge'] . "</td> <td>" . $row['Lied-Nummer'] . "</td></tr>"; }; }; /*if (isset($_POST['submitted'])) { $titel = $_POST['titel']; $artist = $_POST['artist']; $songtitel = $_POST['songtitel']; $musicle = $_POST['musicle']; $liednr = $_POST['liednr']; $data_add = "INSERT INTO cd-titel (CD-Titel, Artist, Songtitel, Musiklänge, Lied-Nummer) VALUES ('$titel', '$artist', '$songtitel', '$musicle', '$liednr')"; if (!mysqli_query($db_name, $data_add)) { die('Fehler beim einfügen von Daten'); } } */ // $data_add = "INSERT INTO `cd-titel` (`CD-Titel`, `Artist`, `Songtitel`, `Musiklänge`, `Lied-Nummer`) VALUES ('$titel', '$artist', '$songtitel', '$musicle', '$liednr')"; // mysqli_query($con, $data_add); /*mysqli_query($con, $data_add);*/ ?> <form methode="post" action="Datenspeichern.php"> <input type="text" name="titel" placeholder="CD-Titel"/> <input type="text" name="artist" placeholder="Artist"/> <input type="text" name="songtitel" placeholder="Songtitel"/> <input type="text" name="musicle" placeholder="Musiklänge"/> <input type="text" name="liednr" placeholder="Lied-Nummer"/> <input type="submit" name="submitted" value="speichern"/> </form> </br></br></br> </table> </body> </html> second code(Datenspeichern.php)= <?php $con = mysqli_connect('localhost', 'root', ''); if (!$con) { echo'Nicht verfügbar'; } if (!mysqli_select_db($con, 'cdaufgabe')){ echo 'Datenbank nicht ausgewählt'; }; $titel = $_POST['titel']; $artist = $_POST['artist']; $songtitel = $_POST['songtitel']; $musicle = $_POST['musicle']; $liednr = $_POST['liednr']; $data_add = "INSERT INTO cd-titel (CD-Titel, Artist, Songtitel, Musiklänge, Lied-Nummer) VALUES ('$titel', '$artist', '$songtitel', '$musicle', '$liednr')"; if (!mysqli_query($con, $data_add)){ echo 'Fehler'; } else { echo'Eingefügt'; }; header("url=CD_Webseite.php"); ?> Does anyone knows the mistake i keep doing?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.