Guestbook problem

Hello!

I need help with my guestbook code. I want to link to the page, where the guestbook actually is. You write all the info on one page. and then gets redirected to the guestbook. now i need a “button” that just shows the guestbook… much easyer to just show the code and explain whats happening

[php]

<html>
<head>
<title>Fælles Forum</title>
</head>
<body>                        
<form action="skriv.php" method="POST">
<br>
 Navn <input type="text" name="fornavn" />
<br>
<br>
E_mail <input type="text" name="email" />
<br>
<br>
<p>Besked<p> <textarea rows="7" name="kommentar" cols="40"></textarea>
<br>
<br>
Adresse <input type="text" "Adreese" name="adresse" />
<br>
<br>
Mobil nr <input type="text" name="mobil" size="12" maxlength="8" 
<br>
<br>
<br>
<input type="submit" value="Save" />
<input type="reset" value="reset"  />
<form action="skriv.php" method="GET">
<INPUT TYPE="submit" VALUE="Read all messages">   // This is where i need to make it link to the guestbook. 
</form>
<FORM METHOD="GET" ACTION="Login.php"> <INPUT TYPE="submit" VALUE="Logout"> </FORM> 
<form action="index.php" method="GET">
<input type="submit" value="Delete all messages" name = "delete">
</form>
<?php
if (isset($_GET['delete']))
{
$handle = fopen("TXTfil.txt", "w");
fclose($handle);
echo "Alle kommentare slettet!";
}
?>


</body>
</html>

[/php]

[php]
// This is where i need to make it link to the guestbook.
[/php]
The problem is that it comes up with an error, because ive said that, if the name, and comment, is empty then… error. But it should not do the same as the “save” button.

here is the other code - Some of it is in danish
[php]

<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<Title>Fælles forum</title>
<h1>Fælles Forum</h1>
</head>
<?php

$dato=date(“d F Y H:i:s A”);
$fornavn = $_POST[“fornavn”];
$email = $_POST[“email”];
$kommentar = $_POST[“kommentar”];
$adresse = $_POST[“adresse”];
$mobil = $_POST[“mobil”];

$fil = fopen(“TXTfil.txt”, “a+”) or exit(“fejl”);

fwrite ($fil, $dato."\n". $fornavn."\n".$email."\n".$kommentar."\n".$adresse."\n".$mobil."\n"."\n");

fclose($fil);
?>
<?php

$fil = fopen("TXTfil.txt", "r") or exit("fejl");

	while(!feof($fil)) {
		echo fgets($fil) ."<br/>";
		}
		fclose($fil);
?>
 
<FORM>

[/php]

Hope you can understand what i mean :stuck_out_tongue:

Try closing the form before you add a new button that does the same thing as the old one.

Hope this helps.

[php]

// This is where i need to make it link to the guestbook. [/php]

Ah. Did not even noticed that. It did do the trick. but now there is a new problem. It now comes up with an “Undefined index” because of these [php]$dato=date(“d F Y H:i:s A”);
$fornavn = $_POST[“fornavn”];
$email = $_POST[“email”];
$kommentar = $_POST[“kommentar”];
$adresse = $_POST[“adresse”];
$mobil = $_POST[“mobil”];[/php]

Also. when i click Send, or just the “view all messages” it prints out the date, as if someone has written something in the guestbook. think my " If statement" is wrong somehow?

Actually it did not do the trick ! :frowning: The problem remains, along with the others

Scratch that I’ll post in a few minutes after looking at your code longer.

–standby

Looking forward to it! These problems are begining to get annoying.

Small update. I made the Undefined index go away. This is the code that actually causes me all the problems, i need to rewrite it think, but i just dont know… to what?

[php]<?php
if (empty($fornavn) || (empty($kommentar)))
{
echo “Du mangler at skrive noget i navn eller kommentar”;
exit;
}

		else
	
$fil = fopen("TXTfil.txt", "r") or exit("fejl");

	while(!feof($fil)) {
		echo fgets($fil) ."<br/>";
		}
		fclose($fil);
?>
 [/php]

Bump

Only problem i still have, is that i cant view the guestbook, without having to submit something to it. That is because of my if empty statement. Can someone help me to rewrite it so it works?

[php]?>
<?php

if (empty($fornavn) || (empty($kommentar)))
{
echo “Du mangler at indtaste Dit navn og/eller skrive en besked”;
exit;
}

else

$fil = fopen(“TXTfil.txt”, “r”) or exit(“fejl”);
while(!feof($fil)) {
echo fgets($fil) ."
";
}
fclose($fil);
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service