Skip Navigation LinksHome > Categories > Code from a Category

Guest Book with their hands on PHP and MySQL



User Name: serfcompany
Name: Serf
Contact Me: www.datawebcoder.com
Home Page: www.datawebcoder.com
php,mysql,javascript,html,css. Preferable working with Zend Framework. Good know javascript. I worked with various, javascript frameworks such as(jquery, YUI3, extjs, sencha touch). [More]
Viewed Times: 11934
Add Date: 02/21/2012
The article discusses how to make a guest book using PHP and MySQL. The source code and some explanation for it. Of course, analyzed the easiest option to create a guest book, without any bells and whistles and extra features.Here are just snippets guestbook.

Our guest book will consist of three php-file, one database and one table MySQL.


Connect to the database, create database and tables for the guest book


File dbconnect.php, is used to hook up to the database server and MySQL database creation and database and necessary tables for the guest book.



Table gb created the needed fields:
username
- user name, leaving a message in the guest; dt - time and date of the message; msg
- message text.

If the database and table already exist, then nothing happens.


If we really want to save on queries to the database, the rows with the creation of a database and creating tables can be moved to a separate *. Php file is an installer, which will need to run only 1 time.

Dbconnect.php file we will load every time there is a need to access the database.


What we have in the database? Display the contents of the guestbook.


The index.php file is used to display the contents of the guest book form and send a message.


Messages output by the guest book next block of code. Entries in turn pulled out of the query to the database. The order of the output is as follows: new records above the old ones. We also call attention to the fact that the lights of even and odd messages may be different colors.


Connect to the database, create database and tables for the guest book


File dbconnect.php, is used to hook up to the database server and MySQL database creation and database and necessary tables for the guest book.



Table gb created the needed fields:
username
- user name, leaving a message in the guest; dt - time and date of the message; msg
- message text.

If the database and table already exist, then nothing happens.


If we really want to save on queries to the database, the rows with the creation of a database and creating tables can be moved to a separate *. Php file is an installer, which will need to run only 1 time.

Dbconnect.php file we will load every time there is a need to access the database.


What we have in the database? Display the contents of the guestbook.


The index.php file is used to display the contents of the guest book form and send a message.


Messages output by the guest book next block of code. Entries in turn pulled out of the query to the database. The order of the output is as follows: new records above the old ones. We also call attention to the fact that the lights of even and odd messages may be different colors.



Form code for sending messages is as follows:



Validation is filling out the form on the client side, which is implemented JavaScript-function splash ()



The data from the form are passed to the file action.php.


Add the entries in the guestbook


File action.php - core guestbook. In this file the data received from the form to send messages and can be done one of two things:

  • Add entries in the guestbook (if the parameter action = add)
  • Delete all records from the guest book (with the parameter action = delete)

  • Note that the case when action = delete can occur only when the command will be transferred manually, by calling action.php? Action = delete.



    File action.php created specifically to not send data to the file index.php. If we send data to index.php, then refresh the page or on the buttons "back", "forward" in the browser, we could meet with the situation of excessive re-sending the data. What led to the creation of duplicate entries in the guestbook and excessive consumer confusion.


    Action.php File does not return to the browser. When the redirect happens action.php the file index.php.

Sanaan Barzinji
Comment #:  83 Replay this Comment Reply this comment Posted on: 7/19/2012

there is no errors shown here, it's perfect

cheers,

Sanaan Barzinji

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Details**:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
 
    
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.