Hallo zusammen,
Ich bin gerade dabei ein Gästebuch zu gestalten und möchte dabei Datum und Zeit des Eintrages mit anzeigen. Das ganze Gästebuch besteht aus folgenden Scripts:
index.php
<html>
<head>
<title></title>
</head>
<body>
<div align="center">
<table width="450" cellspacing="1" cellpadding="3" bgcolor="#000000">
<tr>
<td bgcolor="#e2e2e2" align="center"><h4>Gästebuch Mondscheinkino</h4></td>
</tr>
<tr>
<td bgcolor="#336699" align="center"><A HREF=gbook_new.php>Neuen Eintrag hinzufügen</A></td>
</tr>
</table>
</div>
<br><br>
<?
function datum($_dat)
{
// Wandelt timestamp String in Datum und Uhrzeit um.
$datum=intval(substr($_dat,6,2)).".".intval(substr($_dat,4,2)).".".substr($_dat,0,4)." um ".substr($_dat,8,2).":".substr($_dat,10,2).":".substr($_dat,12,2);
return $datum;
}
$db = mysql_connect("localhost","root","design");
mysql_select_db("kino",$db);
$result=mysql_query("select * from gbook_kino");
while($row=mysql_fetch_array($result))
{
$id=$row["id"];
$titel=$row["titel"];
$eintrag=$row["eintrag"];
$autor=$row["autor"];
$datum=$row["datum"];
?>
<div align="center">
<table width="450" cellspacing="1" cellpadding="3" bgcolor="#000000">
<TR>
<TD bgcolor="#e2e2e2" width="240">
<b>Titel:</b><br> <? echo $titel ?><br>
<b>Eintrag:</b><br> <? echo $eintrag ?><br>
<b>Autor:</b><br> <? echo $autor ?><br>
<b>Letzte Änderung:</b><br><? echo ($datum) ? datum($datum) : "" ?>
</TD>
</TR>
</table>
</div>
<br><br>
<? } ?>
</body>
</html>
gbook_new.php
<?
include("config.php");
mysql_connect($db_host,$db_user,$db_pass) || die("Could not contact mySQL!");
mysql_select_db($db_db) || die("Connected mySQL, but database is unavailable!");
print("
<html>
<head>
<title>Film Eintragen</title>
<SCRIPT LANGUAGE=JavaScript>
function verify_page()
{
{
document.frmRegister.submit();
}
}
</SCRIPT>
</head>
<BODY bgcolor=#336699>
<BR>
<FORM name=frmRegister action=gbook_new_r.php method=post>
<TABLE align="center" cellspacing="1" cellpadding="3" border="0" bgcolor="#ffffff">
<tr>
<td bgcolor="#336699"><b>Eintrag hinzufügen</b></td>
<td bgcolor="#336699"><A HREF=index.php>Zurück zur Übersicht</A></td>
</TR>
<tr>
<TD bgcolor="#336699"> </TD>
<TD bgcolor="#336699"> </TD>
</TR>
<tr>
<TD bgcolor="#336699">Titel:</TD>
<TD bgcolor="#336699"><INPUT name=titel size="10" maxlength="15"></TD>
</TR>
<tr>
<TD bgcolor="#336699">Eintrag:</TD>
<TD bgcolor="#336699"><textarea name=eintrag cols="30" rows="5"></textarea></TD>
</TR>
<tr>
<TD bgcolor="#336699">Autor:</TD>
<TD bgcolor="#336699"><INPUT name=autor ize="20" maxlength="30"></TD>
</TR>
<tr>
<td bgcolor="#336699"> </TD>
<td bgcolor="#336699"><INPUT type=button value="einfügen" ONCLICK=verify_page()> </TD>
</TR>
</TABLE>
</FORM>
</BODY>
</html>
");
?>
gbook_new_r.php
<?
include("config.php");
mysql_connect($db_host,$db_user,$db_pass) || die("Could not contact mySQL!");
mysql_select_db($db_db) || die("Connected mySQL, but database is unavailable!");
// Werte des Formulars
$titel = $HTTP_POST_VARS["titel"]; // [1]
$eintrag = $HTTP_POST_VARS["eintrag"]; // [2]
$autor = $HTTP_POST_VARS["autor"]; // [3]
$datum = $HTTP_POST_VARS["datum"]; // [4]
// in DATENBANK einfügen
$sqlInsert = "INSERT INTO gbook_kino VALUES ('', '$titel', '$eintrag', '$autor', '$datum');";
$result = mysql_query($sqlInsert);
if (mysql_error())
{
echo mysql_error();
exit;
}
// Bestätigung über Eingabe
print("
<html>
<head>
<title>Update erfolgreich</title>
<style>
a:link {color:#ffcc00; text-decoration:none; font-family:arial,helvetica,sans-serif; font-size:9pt;}
a:active {color:#ffcc00; text-decoration:none; font-family:arial,helvetica,sans-serif; font-size:9pt;}
a:visited {color:#ffcc00; text-decoration:none; font-family:arial,helvetica,sans-serif; font-size:9pt;}
a:hover {color:#ffffff; text-decoration:none; font-family:arial,helvetica,sans-serif; font-size:9pt;}
td {font-family:arial,helvetica,sans-serif; color:#ffffff; font-size:9pt;}
</style>
</head>
<BODY bgcolor=#336699>
<TABLE align="center" cellspacing="1" cellpadding="3" border="0" bgcolor="#ffffff">
<tr>
<td bgcolor="#336699"><b>Insert erfolgreich!</b></td>
</tr>
<tr>
<td bgcolor="#336699"><A HREF=index.php>Zurück zur Übersicht</A></td>
</tr>
</table>
</BODY>
</html>
");
?>
Wenn ich nun einen neuen Eintrag hinzufüge, wird mir die Datums- und Uhrzeitanzeige zwar im richtigen Format angezeigt, allerdings immer mit null:
0.0.0000 00.00.00
Wenn ich einen Eintrag direkt mit phpMyAdmin in der Mysql Datenbank mache, wird mir der Timestamp richtig angezeigt, über das Eingabeformular aber nicht. Habe schon einiges ausprobiert aber bis jetzt habe ich das Problem noch nicht lösen können. Vielleicht hat jemand eine Idee was ich hier falsch mache.
Danke im voraus für Eure Hilfe.
lg
Andi