Jump to content

Recommended Posts

Hey!

 

I'm quit new to PHP, and was making a guestbook to practice with reading and writing files. The first piece of code you see is the piece where you enter your response and contact details, here it also shows the previous answers.

 

The second part of the code is "ProcessGastenboek.php" code, which will be executed when confirming the form of the first part of the code.

 

Now the problem is that I am able to read previous (demo) answers from the TXT file, but i'm not able to write something new to the file. What am I doing wrong here?

 

Thanks!

 

 

			<FORM METHOD=POST ACTION="ProcessGastenboek.php"> 

			<TABLE width=510 border=0> 

			<TR>fill in code in the code box</TR><TR> 
			<TD width=102> 
			Naam: 
			</TD> 
			<TD width=408> 
			<INPUT TYPE="text" NAME="naam" value=""  size="66"> 
			</TD> 
			</TR> 
			<TR> 
			<TD width=102> 
			E-mail: 
			</TD>

			<TD width=408> 
			<INPUT TYPE="text" NAME="email" value="" size="66"> 
			</TD>
			</TR>  <TR>  <TD width=102> code: </TD> <TD width=408> <INPUT TYPE="text" NAME="code" value="" size=66></td> 
			</TR> 
			<TR> 
			<TD width=102>
			Uw reactie: 
			</TD> 
			<TD width=408>

			<TEXTAREA NAME="reactie" ROWS="5" COLS="50" value=""></TEXTAREA> 
			</TD> 
			</tr><tr><td><center><input type="submit" value="zenden"></center></td></TR> 
			</TABLE> 

			</FORM>

			<?php	        
			$myFile = "NieuwGastenboek.txt";
							$fh = fopen($myFile, 'r');
							$theData = fread($fh, filesize($myFile)); 
							fclose($fh);
							echo $theData; ?>

 

 


<?PHP 


$naam = $_POST['naam'];

$email = $_POST['email'];

$reactie = $_POST['reactie'];

$code = $_POST['code'];
$uitvoerbestand = "gastenboek.txt"; 


$bestandsindex = fopen($uitvoerbestand,"r");

$thedata = fread($bestandsindex, filesize($uitvoerbestand));

fclose($bestandsindex); 
if($naam != ""   && $reactie != "" && $code=="code")

{

$bestandsindex = fopen($uitvoerbestand,"w");

if($email !="" )

{

	fwrite($bestandsindex, $naam . "&lt <a href=\"mailto:" . $email . "\">" . $email . "</a>&gt zegt op " . 			date("m/d/y",time()) . ":<BR>");
}
else
{
fwrite($bestandsindex, $naam . " zegt op " . date("m/d/y",time()) . 		":<BR>");


} 

fwrite($bestandsindex, $reactie . "<BR>"); 

fwrite($bestandsindex, "<hr>");

fwrite($bestandsindex, $thedata);

}

else echo("foutieve input");
fclose($bestandsindex); 

header("Location: gastenboek.php");
?> 


Link to comment
https://forums.phpfreaks.com/topic/172964-problems-with-making-a-guestbook/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.