Thomassius Posted September 3, 2009 Share Posted September 3, 2009 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 . "< <a href=\"mailto:" . $email . "\">" . $email . "</a>> 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/172964-problems-with-making-a-guestbook/ Share on other sites More sharing options...
ignace Posted September 3, 2009 Share Posted September 3, 2009 $myFile = "NieuwGastenboek.txt"; You are reading from a different file then you are outputting to: $uitvoerbestand = "gastenboek.txt"; PS: Belg of Nederlander? Quote Link to comment https://forums.phpfreaks.com/topic/172964-problems-with-making-a-guestbook/#findComment-911606 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.