Skip Navigation LinksHome > Categories > Code from a Category

Forum, working with database 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: 1326
Add Date: 04/30/2012
For the forum requires Apache Web server with PHP and database MySQL. Script forum.php3 placed in the directory / usr / local / apache / htdocs (no spaces).

Beginning.


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:



Data processing:



Home Forum.


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.


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.