Topic: Creating a Guestbook from Scratch

I have never touched PHP for anything. I want to learn, but I wasn't sure of doing so when I haven't even excelled in Xhtml and CSS, but I am wanting to learn how to make a pretty simple guestbook for a layout like this:

http://adrian-rodriguez.net/NLTTS

I want to learn how to create one instead of finding those free ones with ads on it. Thanks in advance. I have google searched, but came up with places that already presume I know Php.

The reason the "Guests" link doesn't work, is because that's where I am going to put the guestbook.

Last edited by Adrian (2008-04-04 11:53:27)

Re: Creating a Guestbook from Scratch

What really helped me learn PHP from scratch was to watch and follow along with some video tutorials.  I used a different set than these, but the information here should be the same.  I found these two sites that have basically the same information, it just depends on which one you like better.

http://www.killerphp.com/videos/ - this one is good, but I noticed he uses PHP's print instead of echo, which is fine, it's just that echo is more widly used and accepted.  Just makes me wonder how good the rest of the tutorials are.
http://www.phpvideotutorials.com/ - This one also seems good, i like what I saw, but the instructor may be a bit offensive sometimes.  It doesn't bother me, but just letting you know in case that makes a difference to you.

And also, not to steer you off course or anything since PHP is an AWESOME language to learn and something to be able to put on a resume, but just installing Expression Engine on this site may be easier and then just use comments as your makeshift "guestbook".

Re: Creating a Guestbook from Scratch

C.Barr wrote:

And also, not to steer you off course or anything since PHP is an AWESOME language to learn and something to be able to put on a resume, but just installing Expression Engine on this site may be easier and then just use comments as your makeshift "guestbook".

1st- What is express engine?

2nd- I want to learn a bit of PHP to get me started in a new direction in web development. Code wise. I am trying to sharpen and gain more skills in my coding areas, Xhtml, CSS, Html and some php to get started.

Thanks.

Re: Creating a Guestbook from Scratch

Expression Engine is a content management system - http://expressionengine.com - it seems to be all the rage here at Godbit tongue
Check out the "Content Management" forum here and there's a lot of info on it.

I do agree you should learn PHP, if nothing else the absolute basics.  It's been very helpful to me.  (Also, as a bonus, you'll get more programming jokes.)

Re: Creating a Guestbook from Scratch

I have found the W3 Schools PHP pages to be very helpful when trying to acquire some scraps of PHP knowledge. Part of the problem is that there are tonnes of tutorials, lessons, courses out there!

Trying to solve small problems in Frog CMS (which allows you to use PHP directly in its pages/templates) has been the way I have come at it. But I'm just an amateur! smile

David Reimer  //  ↪ "If you know the resurrection is coming, it's impossible to be in utter darkness." — Tim Keller ↩

Re: Creating a Guestbook from Scratch

Thanks for the heads up. I am going to tackle learning some php in the next couple of months along with sharpening whatever Xhtml, and CSS kills I possess. wink Anyway I took a look at the Express Engine site and saw that a lot of online magazines use them. That would be great for my site, but I think I will stick to what I know now, which is WordPress, in which I am still learning how to use, edit, and create a theme of my own. Thanks for your help guys. I will be back....

Re: Creating a Guestbook from Scratch

Ok I got one to work. Well, one that I sort of coded from a tutorial. wink But anyway, please test it.


http://adrian-rodriguez.net/NLTTS/guestbook.php

I will maybe style it later.

Re: Creating a Guestbook from Scratch

Cool, nice work!

Now i think you need to work on cleaning up the data inputs, right now I can submit a completely blank form!  Also, might as well check for a valid email address/links, and to help you out in that department let me just give you this function that I had a hard time locating.

function hyperlink($string) {
  $string = preg_replace("#([\s\(\)])(https?|ftp|news){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^\"\s\(\)<\[]*)?)#ie", '\'$1\'.handle_url_tag(\'$2://$3\')', $string);
  $string = preg_replace("#([\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^\"\s\(\)<\[]*)?)#ie", '\'$1\'.handle_url_tag(\'$2.$3\', \'$2.$3\')', $string);
  $string = ereg_replace('[-a-z0-9!#$%&\'*+/=?^_`{|}~.]+@([.]?[a-zA-Z0-9_/-])*',"<a href=\"mailto:\\0\">\\0</a>" ,$string);
  return $string;
}

That will convert all links and email addresses into clickable links.  I also noticed that line breaks in th comment field are not preserved.  Here's another helpful function I can recommend here that will keep line breaks, preform the stripslashes operation, make links from (using the function above) add the line breaks.  Only use then when getting data OUT of the database!

function clean ($str) {
	$stripped =  stripslashes($str);	
	$breaks = nl2br(hyperlink($stripped));
	return $breaks;
}

I'd put those functions in another PHP file and then just include that file on everything else. That way they're always available to you!

So, when you're on the "view guestbook" page just include/require the functions above, and output data like this:
     echo clean($comments);
Or whatever your variable names are.

Last suggestion!  Reverse the order of the guestbook entries so that the most recent one is at the top!

Looking great man, you've done a lot with PHP from not knowing anything just a short time ago!

Re: Creating a Guestbook from Scratch

lol Well, it was pre-made with a little editing on my part, but I still don't have a clue. I also wanted to place the "viewguestbook.php" and "guestbook.php" into one page which is great, but I don't know how to set it where it shows only the last like 10 comments or so. Also, where do I put those functions???? lol You lost me at....yeah well.....you lost me. wink

Re: Creating a Guestbook from Scratch

Haha, sorry!
Make a new php file, put those in there with nothing else.  If you collect more functions along the way, add them in there too.

On the pages you want to have those functions add this to the top of those pages
include("path/to/functions.php");
and it's exactly like the functions in that file are in the current file you're working on.

For getting it to display "pages" of comments can be a bit tricky.  here's a good tutorial on it, but it may be a bit over your head.  You may want to put that off for a while.

Re: Creating a Guestbook from Scratch

C.Barr wrote:

For getting it to display "pages" of comments can be a bit tricky.  here's a good tutorial on it, but it may be a bit over your head.  You may want to put that off for a while.

Sure is....lol

So when you said ("path/to/functions.php") do you mean the path of the folder where the file is located?

And How to I start a page in php? lol I bet now you don't think that I have any clue. lol DO I start the page just with your function codes, or is it like html where I have to add an opening and clogin <html> tag?

Re: Creating a Guestbook from Scratch

Nope, it's just a page with that.  And of course you'll simple need to put the PHP tags at the front and end.

<?php

//functions go here

?>

Re: Creating a Guestbook from Scratch

ok so I type <?php and place whatever code after two // then close the document with ?> right? And where am I linking to the functions from?

14

Re: Creating a Guestbook from Scratch

Adrian wrote:

... place whatever code after two // then ...

Not quite -- the // is one way of marking comments in PHP. Have a look here, and it might be a good idea just to work through those screens, one at a time. It wouldn't even take that long! wink

David Reimer  //  ↪ "If you know the resurrection is coming, it's impossible to be in utter darkness." — Tim Keller ↩

Re: Creating a Guestbook from Scratch

Thanks I will check that out. I didn't know where to start, but I guess that would help out a lot then.

Re: Creating a Guestbook from Scratch

I'd still highly recommend you watch those tutorial videos I posted above. It's hard to understand a lot of this without any explanation.  I think you said in another thread that you've got some free time right now anyway, and watching these videos to learn a new language would be a great way to spend it!

Last edited by C.Barr (2008-04-06 15:11:19)

Re: Creating a Guestbook from Scratch

Thanks I will definetly do so. brb

Re: Creating a Guestbook from Scratch

C.Barr wrote:

Haha, sorry!
Make a new php file, put those in there with nothing else.  If you collect more functions along the way, add them in there too.

On the pages you want to have those functions add this to the top of those pages
include("path/to/functions.php");
and it's exactly like the functions in that file are in the current file you're working on.

For getting it to display "pages" of comments can be a bit tricky.  here's a good tutorial on it, but it may be a bit over your head.  You may want to put that off for a while.

lol I finally got what you said here. I couldn't get it to work. I added it to addguestbook.php and viewguestbook.php and it didnt work? Do you know what I may have done wrong?

Last edited by Adrian (2008-04-09 11:50:45)

Re: Creating a Guestbook from Scratch

I think I'd have to see your code.

A cool trick when you want to share php code is to make copies of all the files you want to share, and change the extension to .phps - this allows people to see the source code.

Re: Creating a Guestbook from Scratch

Ok, so what do you want me to do? Create a .phps file? How will you see it?

Re: Creating a Guestbook from Scratch

give me a link to the .phps files, and then I'll look at it.

Just make a copy of the file and rename the extension to .phps  this allows the source code to be viewable by anyone - great for debugging and showing to people.

Last edited by C.Barr (2008-04-09 17:24:22)

Re: Creating a Guestbook from Scratch

Ok Will do. I will email them to you.