Hi guys,
I just started learning html, php and sql and I am making a homepage where people can register/login/logout.
I am making a forum where people can leave a reply. This is the code for it:
Quote
<?php
if($_SESSION["berechtigter_User"] != 1)
{
echo "Bitte logge dich ein um einen Eintrag zu verfassen!";
}
else
{
echo "Du bist eingeloggt";
}
?>
<form action = "kontaktundgaestebuch.php" method ="post">
Name:
<input type="text" size = "17" name = "name">
<br clear="all"/>
Kommentar:
<input type = "textfield" style="height: 150px; width: 300px" name = "kommentar">
<br clear="all"/>
<?php echo "Datum: ";?>
<?php
$datum = date("d.m.Y",$timestamp);
echo $datum;
?>
<br clear="all"/>
<input type = "Submit" value = "Abschicken">
</form>
<?php
if (!empty($_POST))
{
$name = $_POST['name'];
$comment = $_POST['kommentar'];
$eintrag = "INSERT INTO gaestebuch (name, kommentar) VALUES ('$name', '$comment')";
$eintragen = mysqli_query($db, $eintrag);
}
?>
<?php
$ergebnis = mysqli_query($db, "SELECT * FROM gaestebuch");
while($row = mysqli_fetch_object($ergebnis))
{
echo $row->name;
echo " schrieb am ";
echo $datum;
echo ": ";
echo $row->kommentar;
echo "<br />";
}
?>
I want however for only people who are logged in to be able to post, however everybody can see the comments.
I tried putting the form in the else {} instead of the "DU bist eingeloggt), but then echo's dont work because if you are not logged in the variables don't exist.
Can anybody help me with this?