30 minutes to use PHP to write a simple address book with a database, page 1/3

Source: Internet
Author: User

Reference the opening remarks of the previous article:

I haven't been in touch with PHP for a long time, so there are some shortcomings. You are welcome to correct them and make everyone laugh.

This tutorial is intended for beginners of PHP. It is the simplest and most basic thing, so experts can skip it.

To help beginners get started as soon as possible, this is the simplest and most basic PHP program. I believe you only need a little basic PHP knowledge, you can learn it in 10 minutes. It doesn't matter if you don't have the basic knowledge of PHP. As long as you read it patiently, you won't learn it for more than an hour.

The purpose of this article is to study and make progress together with everyone, and then drive away PHP beginners from their fear of PHP 108,000, so that everyone can learn PHP more confidently, in fact, PHP is not difficult to learn, as long as you calm down to learn, you will be able to learn something. Okay, now let's get started, or get scolded.

[Design ideas]
Implementation: add, view, modify, and delete basic functions. Let's just start with this.

[Program Planning]
Well, don't be nervous. We won't do any software engineering here, do any requirement analysis, or draw any flowcharts or other things that make people vomit, and I will be flat in a short time. Of course, formal development is required, so be sure to understand it when you are free.

Input. php ---------- form used to add contact information (of course, html can be used, but to avoid confusion, it should be all in the 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 is designed, and four words are written for the sake of good reading. Don't mind. We are not doing anything about modeling here, and we will also vomit blood, huh, huh. Well, we started to suffer a little bit, and we couldn't leave it out of time. I drew a ugly table with characters. No way, that's the level. Let's take a look at it, cry.

____________________________________________________________________________
| FIELD | type | organization | attribute | 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

For more information about databases, see:
Are you familiar with the id? A unique identifier of a group of data. For example, if you are outdated, click your ID to display a bunch of information about you, which is a unique identifier.
Int (10) is the data type, representing a 10-digit integer. UNSIGNED indicates non-negative, and auto_increment indicates auto addition. Because the id is set to automatically add, we don't have to worry about it after creating it, so let it survive, huh, huh.

The name field is used to store the name. Note that the field name can be named at will, for example, "name". But to facilitate the subsequent explanation, please name it with me for the moment. It is recommended that the naming rules be lowercase letters. You can also underline them. Varchar (10) Stores Chinese people. Should 10 words be enough? Haha, no matter what, that's it. Varcha r and char, the former saves space, and the latter saves time ...... Let's get to know about these data types by google. Utf8_general_ci: character set. This is very important. You must be clear about the character set used by your database. Otherwise, a bunch of garbled characters may appear. Speaking of character sets, we strongly recommend that you use utf8.

Sex is used to store gender. Why is the type tinyint (1) and one-bit small integer enough? Of course it's enough. It's okay to use 0 to represent female and 1 to represent male. I just forgot to say something. Some people may not understand it yet. NULL, no, is not empty.

Mobi is also intuitive to get the name. I will bring it quickly below. mobi is used to store mobile phone numbers, of course, 11 digits.

Email is used to store emails. More than 50 emails are needed.

Addr is used to store mailing addresses. The universe, earth, country, province, city, township, town, and village are all written in. It should be enough for 50 people.

Now let's create a database. We recommend that you use phpMyadmin to import the following statements in SQL mode, because this is the most convenient:
Copy codeThe Code is as follows:
Create table 'addr _ List '(
'Id' int (10) unsigned not null auto_increment,
'Name' varchar (10) not null,
'Sex' tinyint (1) not null,
'Mobi' varchar (11) not null,
'Email 'varchar (50) not null,
'Addr 'varchar (50) not null,
Primary key ('id ')
) ENGINE = MyISAM default charset = utf8 AUTO_INCREMENT = 1;

Of course, you can also enter it manually using the MySQL Command Line Client. If you are not tired of it, please note that you should remove all the ''symbols. That is, the strange button on the TAB key. Otherwise, an accident may occur.

Well, let's just wait for you to get the database done first. After playing the word for half a day, your hands are sour and your stomach is hungry. Go to dinner first, and continue later. If there are still 4 points left behind, we hope you can do it as soon as possible. However, it is quite interesting to draw tables with characters.

Well, next we will make web pages and write programs one by one:
The revolution is not yet successful ~ Let's proceed. You need to add: Create a database before importing!
For distinction and convenience, I named the Database list, named the data table addr_list, and wrote the complete SQL statement.
First, create a database list:
  Copy codeThe Code is as follows: create database 'LIST ';
Then create the data table addr_list:
  Copy codeThe Code is as follows: create table 'addr _ List '(
'Id' int (10) unsigned not null auto_increment,
'Name' varchar (10) not null,
'Sex' tinyint (1) not null,
'Mobi' varchar (11) not null,
'Email 'varchar (50) not null,
'Addr 'varchar (50) not null,
Primary key ('id ')
) ENGINE = MyISAM default charset = utf8 AUTO_INCREMENT = 1; well, let's do webpage + write programs now:

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.