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.