30 minutes learn to write a simple directory with a database in PHP 1th 3 page

Source: Internet
Author: User
Tags mysql command line
Cite the opening remarks of the previous article:
I contact PHP is not very long, so there is no shortage of places, welcome you to correct, let everyone laughed at.
This small tutorial object is PHP beginners, are some of the simplest, most basic things, so the master can skip Oh.
In order to allow beginners to bring interest, as soon as possible to get started, here is the simplest and most basic PHP program, I believe that you have a little bit of PHP basic knowledge, within 10 minutes can learn it. Without the basic knowledge of PHP does not matter, as long as the patient look, learn it will not exceed one hours.
I write this article is the purpose, and everyone together to learn, and common progress, and then the PHP beginners to the fear of PHP driven to 108,000 miles away, so that we enhance self-learning php confidence, in fact, PHP is not difficult to learn, as long as the quiet heart to learn, will be able to learn something. Well, say so much nonsense, hurry to start, or be scolded, hehe.
[Design ideas]
Implementation: Add, view, modify, delete, these basic functions, in order to start from the simple, we just do these.
[Program Planning]
Oh, don't be nervous, we will not engage in any software engineering, what needs analysis Ah, draw what flowchart ah such a kind of blood-vomiting things, I will be flat. Of course the formal development of these are necessary oh, so have time to understand.
input.php----------a form for adding contact information (this can be done with HTML, but to avoid confusion, it's all in PHP format)
post.php----------used to process form data
conn.php----------used to connect to the database
show.php----------used to display data
edit.php----------used to modify data
edited.php----------used to process modified data
del.php----------used to delete data
[Data planning]
That is, the database design, in order to look at the point is written four words. Don't mind. We're not going to make any of this here. Modeling, but also vomiting blood, hehe. OK, we started, a bit of pain, not outdated can't, I painted a character with its ugly form, no way, on this level, we will look at it, oh, cry.
____________________________________________________________________________
| field | Type | Finishing | Properties | NULL | Extra |
| ID | Int (10) | | UNSIGNED | No | auto_increment |
| name| varchar (10) | Utf8_general_ci | No | |
| sex | tinyint (1) | No | Mobi | varchar (11) |    Utf8_general_ci | | No | email | varchar (50) | Utf8_general_ci | No | |
| Addr | varchar (50) | Utf8_general_ci No
About the database, I probably say oh:
ID Everyone familiar with it? Unique identification of a set of data. For example, you are in the outdated ID, point your ID will appear a bunch of information about you, this is the only logo.
Int (10) is the data type, representing the 10-bit integer, unsigned is the non-negative meaning, auto_increment is automatically added. Because the ID is set to automatically add, so we build it and then no longer tube, let it go to its own, hehe.
Name This field is used to store the name, note that the field name can be casually named, such as now "name", but in order to facilitate the explanation later, everyone temporarily wronged me to name it. It is recommended that the naming rules be lowercase letters oh, and the middle is underlined. varchar (10) Save the Chinese, 10 words should be enough? Oh, no matter, that's it. Varcha R and Char, the former saves space, the latter saves time ... Pull away, these data types, or everyone's own Google to understand it. Utf8_general_ci, character set, this is very important oh, you must know what character set your database uses, or you will appear a bunch of garbled oh. Speaking of character sets, I strongly recommend that you use UTF8.
Sex is used to store gender, why is the type tinyint (1), 1 small integers enough? Of course enough, imitate the next binary, with 0 for female, with 1 to show the male is OK, just forget to say a little, maybe someone still do not understand, NULL, no, is not empty meaning.
Mobi I get the name is also very intuitive, the following quickly took it, Mobi used to store mobile phone number, of course, 11 bit.
Email is used to store e-mails, 50 should be more than sufficient.
Addr used to store communications address, the universe, the Earth, the state, the province, the city, township, town, village are written in, 50 should also be enough, hehe.
So we're going to create the database now. We recommend that you use phpMyAdmin to import the following statements in SQL mode, because this is the most convenient:

Copy the Code code as follows:


CREATE TABLE ' Addr_list ' (
' id ' int (ten) unsigned not NULL auto_increment,
' Name ' varchar (ten) is not NULL,
' Sex ' tinyint (1) Not NULL,
' mobi ' varchar (one) not NULL,
' Email ' varchar (not NULL),
' Addr ' varchar (not NULL),
PRIMARY KEY (' id ')
) Engine=myisam DEFAULT Charset=utf8 auto_increment=1;


Of course, you use the MySQL Command line client manually input can also Oh, if you are not too tired, hehe, but to pay attention to, is to put all the ' symbols removed. That's the weird button above the TAB key. Otherwise, there might be an accident.
Well, then we have to wait for everyone to get the database done, and then, hit a half-day word, hand good acid, stomach is also very hungry, hehe. First go to eat, a will continue, there are 4 points on the outdated, hope as soon as possible, so you can, but with the character of the form is pretty interesting, hehe.
Well, next we will be a one to do the Web page, one to write the program:
The revolution has not yet been won ~ we go on. Need to add to the above: to create a database before you can import Oh!
To distinguish and facilitate the explanation, I name the database list, name the data table Addr_list, or write out the complete SQL statement.
First create the Database list:

Copy the Code code as follows:

CREATE DATABASE ' list ';


Then create the data table Addr_list:

Copy the Code code as follows:

CREATE TABLE ' Addr_list ' (
' id ' int (ten) unsigned not NULL auto_increment,
' Name ' varchar (ten) is not NULL,
' Sex ' tinyint (1) Not NULL,
' mobi ' varchar (one) not NULL,
' Email ' varchar (not NULL),
' Addr ' varchar (not NULL),
PRIMARY KEY (' id ')
) Engine=myisam DEFAULT Charset=utf8 auto_increment=1;

OK, let's do the Web + Write program now:

Current 1/3 page 123 next page

The above introduces 30 minutes to learn to write a database with PHP simple address Book 1th/3 page, including the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.