Suche nach als

SQLite Formular

Auf dieser Seite:

h2 Titel

Ein Formular zur Eingabe von Inhalten in die SQLite Datenbank unterscheidet sich nicht von einem anderen Formular. Auch das Empfangen der Daten nicht und das Schreiben in die Datenbank habe ich ja schon auf der ersten SQLite Seite demonstriert.

Da ich aber im PHP-Journal so ein Formular fixfertig gefunden habe, möchte ich es hier einsetzen.

Kolonne 1

Kolonne 2


Das Formular kommt so zustande:

<?php
// Formular
$fosqli = <<< _FORMULAR_
<form action="sqlite_form.php" method="post">
  Kolonne 1<br />
  <input type="text" style="width:350px" name="col_1" value="Datensatz:" /><br />
  Kolonne 2<br />
  <textarea style="width:350px" name="col_2" rows="3" cols="150">Wird gefüllt.</textarea>
  <br />
  <br />
  <input type="submit" name="Send" value="Eintragen" />
</form>
_FORMULAR_;
echo 
$fosqli;
?>

sqlite_query($db, $sql)

Das Einlesen kommt so zustande:

<?php
// Einlesen
if (isset($_POST['Send'])){
  
$col_1 htmlspecialchars($_POST['col_1']);
  
$col_2 htmlspecialchars($_POST['col_2']);
  
$db sqlite_open("SQLite/db_test.db"0666$error) or die("Fehler $error");
  
$sql "INSERT INTO tb_test VALUES (NULL, '$col_1', '$col_2')";
  
$doit sqlite_query($db$sql);
  if (
$doit){
    echo 
"<br /><strong>Benutzereingabe erfasst</strong><br />";
  }
}
?>

sqlite_escape_string($userinput)

Das Unschädlichmachen könnte auch statt zuvor wie oben beim Schreiben geschehen: $sql = "INSERT INTO tb_test VALUES ('".sqlite_escape_string($col_1)."','".sqlite_escape_string($col_2)."')");


Valid XHTML 1.0 Check den Code.

WCMS >> << SQLite CSV
Ich bin hier: > PHP Lehrling >>> SQLite Formular
 
HTML und XHTML | CSS | JavaScript und DHTML | PHP und MySQL | Andere Sprachen
Letzter Update: 30.01.2010