Php and mysql message board program implementation code-PHP source code

Source: Internet
Author: User
This program is only for php + mysql fans to learn and test. During the test, errors may occur. Please modify this program according to the error prompt. This program is the installation version and run the install directory first, then follow the prompts! This program is only for php + mysql fans to learn and test. During the test, errors may occur. Please modify this program according to the error prompt. This program is the installation version and run the install directory first, then follow the prompts!

Script ec (2); script


I won't talk about the PHP syntax. Let's talk about connecting to mysql!

The Code is as follows:
$ Conn = @ mysql_connect ("localhost", "root", "mydown") or die ("Database Link error ");
Mysql_select_db ("bbs", $ conn );
Mysql_query ("set names 'gbk '");

The first statement describes the database connection statement. If a database connection error is prompted, the preceding three parameters indicate the database address localhost, and the database username is root, connect to the Database Password mydown;

The second sentence describes the database that $ conn represents when connected to the database table bbs.

The third sentence is to convert the encoding format to display Chinese characters.

After the database is connected, let's take a look at how database statements are submitted and run in PHP!

The Code is as follows:
$ SQL = "INSERT INTO message (id, user, title, content, lastdate) values ('', '$ _ POST [user]', '$ _ POST [title]', '$ _ POST [content]', now ())";
Mysql_query ($ SQL );

We should be familiar with the blue font above, that is, inserting information in the database. The second sentence is to run the statement in the database. Think of variables similar to $ _ POST [title]. You should know that this is the information obtained through Web Page Submission.


Instance

Install

The Code is as follows:



Message board installation




Check_install.php

The Code is as follows:

// Obtain the submitted Database Value
$ Llcc_server =$ _ POST ['llcc _ Server'];
$ Llcc_user_name = $ _ POST ['llcc _ user_name '];
$ Llcc_user_pass =$ _ POST ['llcc _ user_pass '];
$ Llcc_data_name = $ _ POST ['llcc _ data_name '];
// Open the Database Configuration File
$ Fp = fopen ("../config. php", 'w ');

If (! $ Fp ){
Echo "sorry, try again! ";
}
// Write File Content
$ Outconfig =" $ Outconfig. = '$ server = ';
$ Outconfig. = "". $ llcc_server. "; // IP address of the database. If it is local, localhostn is used by default ";
$ Outconfig. = '$ server_name = ';
$ Outconfig. = "". $ llcc_user_name. "; // database connection username, generally rootn ";
$ Outconfig. = '$ server_pass = ';
$ Outconfig. = "". $ llcc_user_pass. "; // database connection password. N ";
$ Outconfig. = '$ server_data = ';
$ Outconfig. = "". $ llcc_data_name. "; // database name n ";
$ Outconfig. = "?> ";
$ Fw = fwrite ($ fp, $ outconfig );

If ($ fw ){
Echo"


Installation complete! Manually delete the install folder in the directory
Back to homepage ";
}


?>

Login. php

The Code is as follows:

Include ("header. php ");
Include ("conn. php ");

If ($ _ GET [out]) {
Setcookie ("cookie", "out ");
Echo"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.