Before we begin consideration of the practical application of PHP, MySQL must be logged in as administrator and create a database which will store all the information.
Create the database forum.
Create three tables in the database forum. There will be written all the information.
User registration in the database.
Next, go pure PHP and HTML.
Generate a form for registration:
Functions used in the form used to verify the information entered by the user. Next, you need to process the data. To connect to the database using the function mysql_connect (). As the need to connect to the database more than once, I learned all of the data to the function connect ()
This function connects the database and check for connection errors. Now you can receive and process user input.
Function print_header ()-is the title of html-pages. It is also used to reduce the amount of code.
Well, that's all. The user is registered and can post messages in the forum.
Create a new topic.
To create a new topic using the form below:
All fields are required. The user must enter the name under which it was recorded in the database and parol.Skript checks them in the database, and if all goes well, puts the message in the table topics.
If the same name and password are entered incorrectly, an error occurs. Put messages can only registered users.
Here's how it looks:
All these precautions are unnecessary. First, for security of the database itself. Second to protect the forum from casual visitors and hacking. A new topic is created and information added to the table topics. Next, we consider how to put the reply message.
Make a reply to the message.
It is no different from creating a new topic, but the answer is placed in the table replies. Generate form.
And data processing:
With that, I think everything is clear, as well as in the previous example.
Reading the topic.
This is a rather extensive part of the script, along the way, I'll give explanations.
That's it. Now you see how easy it is to work with the database using PHP, and how it makes life easier. All this behind the scenes, and visitors can see a regular forum html-page. Next, consider how you can edit the message.
Reply to this post.
Editing posts may be needed if the user made ??a mistake or want to change anything in the text.
You can only edit their own posts, this is followed by the script and database.
Depending on whether the message topics or reply to topic, are displayed two different forms.
Next, you can read and process the data.
As you can see, nothing new.
The same SQL-queries in conjunction with PHP-functions.
If a user forgets a password.
If a user forgets a password, it is enough to enter your e-mail, which he indicated at registration, and your password will be sent to him on this e-mail. The form to enter:
So we got to the end, or rather before, the main board page, which displays a list of topics, the number of answers by topic, date, topic and date of the last answer.
Basically, nothing new. Number of records per page and limited to 20.
Of course, this forum is not an example to follow. Each has its own style of programming. Maybe the other will write it on their own. However, the basis can be taken.