Php+mysql Message Book _php tutorial

Source: Internet
Author: User
Tags myadmin
Learning to program, I think the most important thing is hands-on practice. Today's first day of learning PHP (as the current mainstream development language) ~ ~ ~ to familiarize myself with this language ~ ~ ~ I began to make a PHP (as the current mainstream development language) +mysql (and PHP collocation of the best combination) of the message book.
From easy to difficult ' ~ ~ ~ First by a simple start. The function is gradually perfected.

The most basic function of message book is:
1: User Write message
2: Write data to the database
3: Show All messages

I'm going to start making my message book.

First in PHP (as the current mainstream development language) MyAdmin set up a Guest_book database and then set up a contents table under the database set up two fields under the table
Name and content, respectively
The SQL statements are as follows:
CREATE TABLE ' contents ' (
' id ' int (one) not NULL auto_increment,
' Name ' varchar (a) Not NULL default "No Name",
' Content ' Mediumtext not NULL,
Prima (the most complete virtual hosting management System) RY KEY (' id ')
) Type=myisam auto_increment=6

OK, the database has been built ~ ~ ' to start writing programs
The program contains three pages post.htm (message submission page) index.php (as the current mainstream development language) (Message Display page) updata.php (as the current mainstream development language) (the page that writes data to the database)

The post.htm code is as follows:



Message Book




Updata.php (as the current mainstream development language) page code is as follows:
$name =$_post[user_name];
$content =$_post[post_contents];
$conn =mysql (and PHP collocation of the best combination) _connect ("localhost:6033", "Root", "");
MySQL (and PHP collocation of the best combination) _query ("Set names Utf-8"); Solve Chinese garbled problem
MySQL (and PHP collocation of the best combination) _select_db ("Guest_book");
$exec = "INSERT into contents (name,content) VALUES (". $_post[user_name]. ",". $_post[post_contents]. ")";
$result =mysql (the best combination with PHP) _query ($exec);
?>


index.php (as the current mainstream development language) page code is as follows:

$conn =mysql (and PHP collocation of the best combination) _connect ("localhost:6033", "Root", ""); Open MySQL (best combination with PHP) server connection
MySQL (and PHP collocation of the best combination) _select_db ("Guest_book"); Link Database
MySQL (and PHP collocation of the best combination) _query ("Set names Utf-8"); Solve Chinese garbled problem
$exec = "SELECT * from Contents"; SQL statements
$result =mysql (the best combination with PHP) _query ($exec); Executes the SQL statement and returns the result
while ($rs =mysql (the best combination of PHP collocation) _fetch_object ($result))
{
echo "


"; Echo"
Name: ". $rs->name."
Message: ". $rs->content."

";
}?>


As for paging, page steering and other functions temporarily do not go up. To make the program as concise as possible. But the core functions of the message book are all here.

I need to say a few more words.

$conn =mysql (and PHP collocation of the best combination) _connect ("localhost:6033", "Root", "");
This sentence is very important at first I used the $conn =mysql (and PHP collocation of the best combination) _connect ("127.0.0.1", "", "");
How to get out of the data into the database to ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ after watching for a long time to know which 127 of the original place should be in PHP (as the mainstream development language now) MyAdmin look at the server name hit the database port is what ~ ~ ~ There is also root there is MySQL ( and PHP collocation of the best combination) user name, followed by the password

Another problem is the problem of Chinese characters garbled

_query ($exec) in $result=mysql (the best mix with PHP); The statement is preceded by MySQL (the best combination with PHP) _query ("Set names gb2312") or MySQL (the best combination of PHP collocation) _query ("Set names Utf-8");
Suspicious the Chinese characters submitted into the database are stored in the database in garbled form, and the data containing Chinese characters from the database are prevented from being queried in garbled

http://www.bkjia.com/PHPjc/508915.html www.bkjia.com true http://www.bkjia.com/PHPjc/508915.html techarticle Learning to program, I think the most important thing is hands-on practice. Today's first day of learning PHP (as the current mainstream development language) ~ ~ ~ to familiarize myself with this language ~ ~ ~ I began to make a PHP myself (as now ...

  • Related Article

    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.