Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Daten aus Formular in MySQL schreiben...was mach ich falsch ?

Empfohlene Antworten

Veröffentlicht

Hi ich habe folgenden Code:

<?php

//einfuegen.php

error_reporting(E_ALL);

$Verfasser = $_POST['Verfasser'];

$Titel = $_POST['Titel'];

$Text = $_POST['Text'];

$insert = "INSERT INTO news[(Verfasser, Titel, Text)]

VALUES('$Verfasser', '$Titel', '$Text')";

include("connect.php");

mysql_query($insert);

?>

--------------------------------------------------------------------

<?php

//connect.php

error_reporting(E_ALL);

include("constant.php");

@mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) OR

die("Verbindung nicht realisierbar, Fehlermeldung:".mysql_error());

mysql_select_db(MYSQL_DATABASE) OR

die("Datenbank nicht gefunden, Fehlermeldung: ".mysql_error());

?>

--------------------------------------------------------------------

<?php

//constant.php

define('MYSQL_HOST', 'localhost');

define('MYSQL_USER', 'root');

define('MYSQL_PASS', '');

define('MYSQL_DATABASE', 'news');

?>

--------------------------------------------------------------------

//eingabe.php

<form action="einfuegen.php" method="post">

<table align="center">

<tr>

<td align=left>Verfasser:</td>

</tr><tr>

<td><input name="Verfasser" size=30 maxlength=30></td>

</tr><tr>

<td align=left>Titel:</td>

</tr><tr>

<td><input name="Titel" size=30 maxlength=50></td>

</tr><tr>

<td align=left>Text:</td>

</tr><tr>

<td><textarea name="Text" rows=10 cols=50></textarea></td>

</tr><tr>

<td><input type=submit value="Absenden">

<input type=reset value="Abbrechen"></td>

</tr>

</table>

</form>

--------------------------------------------------------------------

So nun habe ich das Problem, das wenn ich was eingebe und absende, es niemals in der Datenbank landet !

Warum was mach ich flasch ?

Formular 1 (Dateneingabe, deindateiname.php):

<form action="einfuegen.php" method="post">

<table align="center">

<tr>

<td align=left>Verfasser:</td>

</tr><tr>

<td><input name="Verfasser" size=30 maxlength=30></td>

</tr><tr>

<td align=left>Titel:</td>

</tr><tr>

<td><input name="Titel" size=30 maxlength=50></td>

</tr><tr>

<td align=left>Text:</td>

</tr><tr>

<td><textarea name="Text" rows=10 cols=50></textarea></td>

</tr><tr>

<td><input type=submit name="senden" value="senden">

<input type=reset value="Abbrechen"></td>

</tr>

</table>

</form>

Formular 2 (Speichern, einfuegen.php):

<?php

if(isset($_POST['senden])):

/* Deklaration der übergebenen Variablen */

$verfasser = $_POST['Verfasser] ;

$Titel = $_POST['Titel'];

$Text = $_POST['Text'] ;

$table = DeineTabelle; ""War Deinem Quelltext nicht entnehmbar!! Oder ist sie news wie die db = news heisst!""

$link = mysql_connect("localhost", "root", "")

or die("Keine Verbindung möglich: " . mysql_error());

mysql_select_db("news") or die("Auswahl der Datenbank fehlgeschlagen");

/* eintragen der neuen daten */

$sql ="INSERT INTO $table (verfasser, titel, text) VALUES ($verfasser, '$titel, '$text')";

mysql_query($sql,$link);

echo "'Die daten Daten wurden erfolgreich hinzugefügt'<br>";

else:

@require("deindateiname.php"); ""Name Deiner Formular Datei !!!""

exit;

endif;

?>

End

So müsste eigentlich so klappen, habs versucht mal auf Deine Daten abzustimmen, wenn du ne id-spalte hast die autoincrement ist oder so dann muss noch bei der sql anweisung ne NULL und ID rein,sieht dann so aus:

$sql ="INSERT INTO $table (id ,verfasser, titel, text) VALUES (NULL,$verfasser, '$titel, '$text')";

Na dann...

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.