PHP - Guestbook

Any other programming language that is not covered in the Web Scripting category.

Postby darkwizzard on Tue May 23, 2006 11:30 am

Well I gues it's usefull for starting to learn.But there are many opensource guestbooks outhere.Look at this one: http://nrg88.4ya.us/page_8_1.html
One of my friends has made it.
It's good if you're a newby in php.
darkwizzard
Contributer
Contributer
 
Posts: 32
Joined: Tue May 23, 2006 10:41 am

php guestbook

Postby lyndz on Wed May 24, 2006 3:27 am

how could i view the queries?
Software is like sex: It's better when it's free. -Linus Torvalds-
Image
lyndz
Contributer
Contributer
 
Posts: 71
Joined: Tue Apr 18, 2006 6:51 am
Location: Republika ng Pilipinas

Re: php guestbook

Postby Rommaster on Wed May 24, 2006 10:41 am

lyndz wrote:how could i view the queries?


What queries do you mean?

Code: Select all
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO contacts VALUES ('','$first','$last','$email','$web','$comment')";
mysql_query($query);
SwiftIRC - irc.swiftirc.net - #phoenix
Phoenix-Network

(\__/)
(='.'=) This is Bunny. Copy and paste bunny into your
(" )_(" ) signature to help him gain world domination.
Rommaster
Phoenix Veteran
Phoenix Veteran
 
Posts: 960
Joined: Thu Mar 10, 2005 1:05 pm
Location: The Netherlands

Re: php guestbook

Postby lyndz on Fri May 26, 2006 4:54 am

Rommaster wrote:
lyndz wrote:how could i view the queries?


What queries do you mean?

Code: Select all
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO contacts VALUES ('','$first','$last','$email','$web','$comment')";
mysql_query($query);


I mean, how can I view the Signees to the page? I already tried it but, process.php return nothing
Software is like sex: It's better when it's free. -Linus Torvalds-
Image
lyndz
Contributer
Contributer
 
Posts: 71
Joined: Tue Apr 18, 2006 6:51 am
Location: Republika ng Pilipinas

Re: php guestbook

Postby Rommaster on Fri May 26, 2006 10:28 am

lyndz wrote:
Rommaster wrote:
lyndz wrote:how could i view the queries?


What queries do you mean?

Code: Select all
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO contacts VALUES ('','$first','$last','$email','$web','$comment')";
mysql_query($query);


I mean, how can I view the Signees to the page? I already tried it but, process.php return nothing


You will have to create your own query for that.
Example:

SELECT * FROM VALUES;

This will list all the information from the table 'VALUES'. You have to save it into a variable. And print it.(in tables)

[edit] Also process.php is for the user to input data into the guestbook, not for showing the list of messages the guests left behind.
SwiftIRC - irc.swiftirc.net - #phoenix
Phoenix-Network

(\__/)
(='.'=) This is Bunny. Copy and paste bunny into your
(" )_(" ) signature to help him gain world domination.
Rommaster
Phoenix Veteran
Phoenix Veteran
 
Posts: 960
Joined: Thu Mar 10, 2005 1:05 pm
Location: The Netherlands

Postby chiron on Fri May 26, 2006 5:49 pm

Your forgetting about the people without access to MySQL. Flat file databases are the way foward.

Code: Select all

<form action="guestbook.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
Comments: <textarea rows="6" name="comments" cols="27"></textarea>
<input type="Submit" name="submit">
</form>
<br>

<?php

isset($_POST['submit']) ? WriteEntry() : DisplayEntries();

function WriteEntry() {
   if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['comments'])) {

      str_replace("!", "!", $_POST);
      $string = $_POST['name'] . "!" . $_POST['email'] . "!" . $_POST['comments'] . "\r\n";
      $handle = fopen("guestbook.txt", "ab");
         fwrite($handle, $string);
         fclose($handle);
      DisplayEntries();
   } else {
      print "Please fill in all fields<br>";
      DisplayEntries();
   }
}

function DisplayEntries() {
   $string = @file("guestbook.txt");
   if (!$string) {
      die();
   }
   foreach ($string as $i) {
      trim($i);
      list($name, $email, $comments) = explode("!", $i);
         print "<hr><br><b>Name:</b> " . $name . "<br><b>Email:</b> " . $email . "<br><b>Comments:</b> " . $comments . "<br>";
   }
}

?>   
chiron
Newbie
Newbie
 
Posts: 9
Joined: Fri May 26, 2006 5:01 pm
Location: England

Qoute: PHP Guestbook

Postby lyndz on Sat May 27, 2006 3:29 am

chiron wrote:Your forgetting about the people without access to MySQL. Flat file databases are the way foward.

Code: Select all

<form action="guestbook.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
Comments: <textarea rows="6" name="comments" cols="27"></textarea>
<input type="Submit" name="submit">
</form>
<br>

<?php

isset($_POST['submit']) ? WriteEntry() : DisplayEntries();

function WriteEntry() {
   if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['comments'])) {

      str_replace("!", "!", $_POST);
      $string = $_POST['name'] . "!" . $_POST['email'] . "!" . $_POST['comments'] . "\r\n";
      $handle = fopen("guestbook.txt", "ab");
         fwrite($handle, $string);
         fclose($handle);
      DisplayEntries();
   } else {
      print "Please fill in all fields<br>";
      DisplayEntries();
   }
}

function DisplayEntries() {
   $string = @file("guestbook.txt");
   if (!$string) {
      die();
   }
   foreach ($string as $i) {
      trim($i);
      list($name, $email, $comments) = explode("!", $i);
         print "<hr><br><b>Name:</b> " . $name . "<br><b>Email:</b> " . $email . "<br><b>Comments:</b> " . $comments . "<br>";
   }
}

?>   



..ok.. I'll try it (no mysql needed..)..
Software is like sex: It's better when it's free. -Linus Torvalds-
Image
lyndz
Contributer
Contributer
 
Posts: 71
Joined: Tue Apr 18, 2006 6:51 am
Location: Republika ng Pilipinas

Postby tomyssj4ever on Sun Jun 11, 2006 6:40 pm

Thanks for the help it is great for beginer like i am in php
tomyssj4ever
Contributer
Contributer
 
Posts: 21
Joined: Sun Jun 11, 2006 11:49 am
Location: Romania

Previous

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron