 |
 |
Guestbook not working...
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
Hi guys,
I'm trying to write a guestbook for a site I'm making, and it should write to a text file, I get no parse errors so I don't see why it shouldn't work. The problem is, when I first load up the guestbook page, I type in something in the boxes, then click submit. Nothing appears, I then try again with different text. And the text I typed in before appears. Try it out on the url at the bottom
Here is the php code:
[php]
<?php
if (($username != "") && ($username != ""))
{
$gbFile = fopen("includes/guestbook.txt", "a");
fputs($gbFile, "
Name: $username<br />
Email: $usermail<br />
Comments: $usercomments<hr />");
}
?>
<?php
include "includes/guestbook.txt";
?>
[/php]
And here is the form html:
Code:
<form action="index.php?page=guestbook" method="post">
<p>
<h2>Name:</h2>
<input class="contactForm" type="text" name="username" value="name">
</p>
<p>
<h2>Email:</h2>
<input class="contactForm" type="text" name="usermail" value="name">
</p>
<p>
<h2>Comment:</h2>
<textarea class="contactForm" rows="3" name="usercomments">name</textarea>
</p>
<input type="submit" value="Submit Form">
</form>
The url for all this is here.
Hope you guys can help,
Oliver
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Status:
Offline
|
|
Have you tried closing the file pointer? After writing your data try:
fclose($gbFile);
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
I tried what you said, closing the file:
[php]
<?php
if (($username != "") && ($username != ""))
{
$gbFile = fopen("includes/guestbook.txt", "a");
fputs($gbFile, "
Name: $username<br />
Email: $usermail<br />
Comments: $usercomments<hr />");
fclose($gbFile);
}
?>
[/php]
But it seems that its still the same problem, any other ideas?
Thanks,
Oliver
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Status:
Offline
|
|
What you're doing is taking the data from the user and then writing it to the file, and then including the file. Perhaps there would be less overhead if you put the data you wanted to save into a variable like $myData. Save myData to the file.. close the file and then echo $myData. This saves the step of having to read or include the file. Am I understanding this correctly?
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
Originally posted by Synotic:
What you're doing is taking the data from the user and then writing it to the file, and then including the file. Perhaps there would be less overhead if you put the data you wanted to save into a variable like $myData. Save myData to the file.. close the file and then echo $myData. This saves the step of having to read or include the file. Am I understanding this correctly?
I'm a bit new to PHP (really new infact  ) is there any example code for something like this? Is this why my guestbook isn't working?
Thanks,
Oliver
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
I think I'm close to figuring this out. So I have a blank text file, I go into my form and fill it in and click submit, it shows nothing. I reload the .txt file in a browser and I can see what I typed in. I then refresh the guestbook and see my entry is there. So I'm wondering why isn't it showing it on the page straight away after I've submitted it. I have had an idea to maybe, when they click submit, transfer the user to a Thank You page and then letting them click back. How could this be done? (novice at forms as well as php too  ).
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
Right, to load a different page after clicking submit, I used this code:
[php]
<?php
$redirecturl ="index.php?page=thankyou";
if (($username != "") && ($username != ""))
{
$gbFile = fopen("includes/guestbook.txt", "a");
fputs($gbFile, "
Name: $username<br />
Email: $usermail<br />
Comments: $usercomments<hr />");
fclose($gbFile);
}
header("Location: $redirecturl");
?>
[/php]
But I seem to get the error:
Warning: Cannot modify header information - headers already sent by (output started at /home/.padua/talacia/talacia.com/puertobanus/index.php:9) in /home/.padua/talacia/talacia.com/puertobanus/includes/guestbook.inc on line 42
I have no idea what this means except that it may have something to do with me using index.php?page=guestbook?
Any ideas?
Oliver
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Dec 2002
Status:
Offline
|
|
You have to set header info before you can do anything else. If the thank you page is always in the same place, just use a META redirect with HTML.
|
|
Travis Sanderson
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|