Help - Search - Members - Calendar
Full Version: PHP Guestbook Problem
BleepingComputer.com > Internet & Networking > Web Site Development
   
Fett 1138
Ok, I admit it, this is basically a follow-up of my "HTML Guestbook Will Not Work" ( http://www.bleepingcomputer.com/forums/topic267704.html ) topic, but since I switched to PHP I figured I should create a new topic.

Anyway, I've been having some trouble getting the guestbook on my website ( http://www.fett1138.net ) to work properly. At first I used html, and got nowhere, then flash, also didn't work out for me, so now I'm trying to use php. I got some code for a guestbook that writes to a txt file at [ http://www.webmasterworld.com/forum88/1104.htm ] because I don't really want to use MySQL. Some people have made that code work, NOT ME.

I edited the code for my own use, which can be seen below...
CODE
<h5>Please type your comment and screen name below and press 'Submit' to add it.</h5>
<form method="post" action="">
Name: <br />
<input type="text" name="name" size="30">
<br>
E-mail: <br />
<input type="text" name="email" size="30">
<br>
Website: <br />
<input type="text" name="homepage" size="30" value="http://">
<br>
Comment: <br />
<textarea name="message" wrap="VIRTUAL" cols="50" rows="5"></textarea>
<br>
<input type="hidden" name="from" value="<? echo $HTTP_REFERER ?>">
<input type="submit" name="Submit" value="Submit"> <input type="reset" name="Reset value="Reset>
</form>
<div class="credits">
------------------------------------------------------------------------------------------------
</div>
<h3>Comments</h3>
<!-- start php code -->

<?
if ($message)
{
$name = strip_tags($name);
$email = strip_tags($email);
$homepage = strip_tags($homepage);
$message = strip_tags($message);
$message = ereg_replace("\r\n\r\n", "\n<P>", $message);

if (get_magic_quotes_gpc())
{
$message = stripslashes($message);
$name = stripslashes($name);
}

$date = date("l, F j Y");
$message = "<B>$name </B> -- $date -- <a href=mailto:$email>$email</a><br>$message<br><a href=$homepageurl>$homepagename</a><br>Refered by $from<br><br>\r\n";

$textfile = "guestbook.txt";
if ($fp = @fopen ($textfile, "r"))
{
$oldmessages = @fread($fp,filesize($textfile));
@fclose(fp);
}

$fp = fopen ($textfile, "w");
fwrite ($fp, $message);
fwrite ($fp, $oldmessages);
fclose ($fp);
}

@readfile("guestbook.txt");
?>

<!-- end php code -->


I have uploaded "guestbook.txt" and set CHMOD on both "guestbook.php" and "guestbook.txt" to 777.

If anyone who has more php experience than me could tell me what the problem is, it would be greatly appreciated! smile.gif

Thanks
KamakaZ
Have you got the files in the same directory? And does your server support PHP?
Fett 1138
I honestly can't imagine that they don't support PHP, but I'll try to call them when I get the free time, and yes they're all on the same directory. I honestly don't understand why these things seem to refuse to work for me when they obviously work for other people.

Also, a very simple question for someone who knows PHP, how can I make the "Website" field optional?

UPDATE: I contacted GoDaddy by email and asked if they did not support PHP, and what they think the problem is.
Romeo29
Godaddy supports both PHP and ASP.
Godaddy is a huge web hosting service provider, you should expect them to support all the popular stuff.

http://www.godaddy.com/hosting/web-hosting.aspx#details
Fett 1138
Ok, I contacted GoDaddy, and they assured me that they support PHP, but didn't tell me what the issue might be. I honestly don't understand why it's taking so long to figure out something that should be moderately simple.

And again, how might I make the website field optional?
groovicus
QUOTE
And again, how might I make the website field optional?


By definition, all fields are optional. If a developer requires that a field be mandatory, then before the data is submitted, javascript is used to make sure that the field has been populated.

QUOTE
I contacted GoDaddy, and they assured me that they support PHP, but didn't tell me what the issue might be

It is not their job to figure out what is wrong with your code.
Romeo29
You should install WAMP and test your code locally before you upload to server. BY default WAMP shows all errors in PHP so you can find out what problem you are having.

http://www.wampserver.com/en/
Fett 1138
I installed WampServer 2 and have it running but I honestly have no idea how to test the code, I looked through the WAMP website and couldn't find anything helpful.
Romeo29
Assuming you installed WAMP in c:\wamp

C:\wamp\www becomes your web site folder, similar to folder you would upload files to at godaddy. Treat it in similar manner.
Copy your code files to c:\wamp\www.
Make sure wampserver is running (in system tray a speedometer like icon). If not run it from Start Menu > WampServer > start wampserver. In Vista and 7 you would need to give permission to run as server. If the icon is red in color, click on it and select start all services.
Open browser and type 127.0.0.1 in the address field to check your local website.
If your code file was c:\wamp\www\guestbook.php type in browser http://127.0.0.1/guestbook.php

Using WAMP in this way makes it easier and faster to test and fix web sites at your own computer before you upload the files and make them public.

By default WAMP has configured php.ini to show all errors (which you wont see on an online web server because most servers have them disabled by default). So if your PHP code is not working, you will see which line in your php code is causing what error right in your browser. You can debug and fix your code using that information.
KamakaZ
Try this. It is one i made earlier on this year, feel free to use/modify it but please leave the link at the bottom of the form and the information at the start...

A download is avaliable here.

It writes to a .dat file and also checks for blank fields, future updates will have spam prevtion included, but need to find some free time...

Good luck

~Kam
KamakaZ
found some free time and added the spam smile.gif

(for some reason i can't edit my post above?? any idea's?)

~Kam
Fett 1138
I used KamakaZ's code and uploaded the file to my website, I made some (seemingly) harmless cosmetic changes (removed the "My Guestbook" title, moved "* Marks a required field" up in the page, and changed "Previous Entries:" to "Comments:".) Whenever I look at the page the whole "<!--------------------------------------------------------------------------------- Author: Bradly Sharpe Copyright © 2009 ..." is visible along with...


"Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/content/f/e/t/fett1138/html/guestb.php on line 103

Warning: include(http://202.45.110.174/code/include.php) [function.include]: failed to open stream: no suitable wrapper could be found in /home/content/f/e/t/fett1138/html/guestb.php on line 103

Warning: include() [function.include]: Failed opening 'http://202.45.110.174/code/include.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/content/f/e/t/fett1138/html/guestb.php on line 103"


Other than that, comments CAN BE POSTED, so all I want to do is remove the warnings and make the first part (the <!--- part) not viewable on the page

The page can be viewed at http://www.fett1138.net/guestb.php

Anyone know what the problem could be?

UPDATE: I Fixed the warnings by replacing "<? include('http://202.45.110.174/code/include.php')?>" with the actual code from [ http://202.45.110.174/code/include.php ], but the other part (the <!--- part) is still there.

EDIT:
It seems to me that the only way to fix the "<!--- part" is to remove it, but then I'm no PHP expert.
KamakaZ
<!-- stuff --> is a HTML comment, i'm guessing you've placed it between <?php ?> tags, so replace the <!-- with /* and the --> with */ which should get rid of your problem.

Does the spam filter work for you? Try add a comment with xxx in the message/comment field, you should get an error message then redirected.


Hope all goes well,

~Kam

(I do have to agree with groovicus, that if you did spend a couple of hours LEARNING php, then you could have created something similar within 2-3 hours.)

EDIT: If spam filtering doesn't work, a pm if you want to resolve it, otherwise i'm glad to see your issue is finally sorted smile.gif
Fett 1138
Thank you, I'm trembling out of excitement right now, I've been working on that thing for several weeks now and only once before this got it to post a comment that disappeared after the first refresh! I apologize for all the trouble that I've put you, and every one else who's helped me on this through. Thank for that code, it's the only thing that worked!

Again, I can't thank you enough!,
Fett1138 thumbup2.gif
groovicus
QUOTE
Thank you, I'm trembling out of excitement right now, I've been working on that thing for several weeks now


Welcome to the world of development. I have often spent days and weeks trying to accomplish some task, and when I di, I want to rip off my clothes and run up and down the hallways screaming. smile.gif It's not a pretty picture, I know.
Fett 1138
Ok, I have no idea what the heck is wrong now, but the file will not work on my website. I uploaded it, went to the page, and it was blank. I checked page source... blank! I know the file works because I've tested it offline. I've tried to upload it on both my desktop and my laptop.

Now I checked the ftp index on my site and it showed up fine!

UPDATE: Never mind, I guess all it needed was time. smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.