

Code: Alles auswählen
<?
$dbname = "deine_datenbank";
$dbhost = "localhost";
$dbuser = "benutzer";
$dbpwd = "****";
$link = mysql_connect($dbhost, $dbuser, $dbpwd);
mysql_select_db($dbname);
if($_POST['text'] || $_POST['button'])
{
$text = $_POST['text'];
if(!mysql_query("INSERT INTO texte (text) VALUES ('$text')", $link)
{
die("Schreiben nicht möglich");
}
}
?>
<html>
<head>
<title>Text aus Form in Datenbank schreiben</title>
</head>
<body>
<form name="<?=$_SERVER['PHP_SELF'];?>" method="post">
<textarea name="text" cols="6" rows="60"></textarea>
<input type="submit" value="speichern" name="button">
</form>
</body>
</html>
Obacht! Das ist eine offene Einladung für SQL-Injections. Besser:StarWolf3000 hat geschrieben:Text statt in Datei in Datenbank speichernCode: Alles auswählen
$text = $_POST['text']; if(!mysql_query("INSERT INTO texte (text) VALUES ('$text')", $link)
Code: Alles auswählen
$text = mysql_escape_string($_POST['text']);