PHP: Datenbank
Verfasst: Mi Feb 03, 2010 7:27 pm
Wie kann ich in die Datenbank schreiben???
Formular:
Der Skript der schreiben soll:
id=int, alles andre String.
Formular:
Code: Alles auswählen
<form name="newGuestBookEntry" action="newguesttodb.php" method="post" width="100%">
<pre>
Anezigename: <input type="text" size="20" name="user" value="'.$username.'">
<textarea type="editor" cols="50" rows="5" name="text">'.$text.'</textarea>
<input type="submit" value="Absenden" name="send">
</pre>
</form>
Code: Alles auswählen
<?php
$hoster=$_POST['user'];
if (array_key_exists('text',$_POST))
{
$entry=$_POST['text'];
}
else
{
echo('<SCRIPT LANGUAGE="JavaScript">location.href="index.php?position=newGuest&err=falseEntry&usr='.$hoster.'";</SCRIPT>');
};
if ( array_key_exists('user',$_POST))
{
$hoster=$_POST['user'];
}
else
{
echo('<SCRIPT LANGUAGE="JavaScript">location.href="index.php?position=newGuest&err=falseName&text='.$entry.'";</SCRIPT>');
};
$db = new mysqli('localhost', 'root', '', 'racing');
$abfrage = $db->query("SELECT
id
FROM
`guestbook`");
$a=1;
while ($guestbook = $abfrage->fetch_assoc())
{
$guestID[$a]=$guestbook['id'];
$a++;
};
$entryID=count($guestID);
$entryID=$entryID+1;
$paste = $db->query("INSERT INTO `guestbook` (
`id` ,
`entry` ,
`hoster` ,
`date`)
VALUES (
'".$entryID."',
'".$entry."',
'".$hoster."',
'".date('d. m. Y')."'");
echo('<SCRIPT LANGUAGE="JavaScript">location.href="index.php?position=guestbook#'.$entryID.'";</SCRIPT>');
?>