Refer to the opening remarks of the previous article:
I am not in touch with PHP for a long time, so there is no shortage of places, you are welcome to correct, let everyone laughed at.
This small tutorial is the object of PHP beginners, are some of the simplest and most basic things, so the masters can skip Oh.
In order to allow beginners to mention interest, as soon as possible, here is written will be the simplest, most basic PHP program, I believe you as long as a little bit of PHP basic knowledge, within 10 minutes can learn it. No basic knowledge of PHP does not matter, as long as the patience to look at it will not be more than one hours of learning it.
The purpose of my writing this article is to and everyone together to learn, common progress, and then the PHP beginners to the fear of PHP driving to 108,000 miles away, so that everyone to enhance the confidence of self-study PHP, in fact, PHP is not difficult to learn, as long as the quiet heart to learn, must be able to learn something. Well, said 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 this.
[Program Planning]
Oh, do not be nervous, we will not engage in what software engineering, what needs analysis, ah, draw what flow chart ah and so vomiting blood things, I was flat. Of course the formal development of these are necessary oh, so have time to go to understand.
input.php----------A form to add contact information (of course this can be used in HTML, but in order to avoid confusion, all unified into PHP format bar)
post.php----------used to work with 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, database design, in order to look at the point is written four words. Don't mind. We also do not engage in what to pull the egg modeling, also will vomit blood, hehe. Well, we started, pain a little, not outdated can not be screenshots, I used to draw a character of its ugly table, no way, on this level, we will look at it, hehe, cry.
____________________________________________________________________________
| Fields | 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 roughly say oh:
ID you're familiar with it? A unique identification of a set of data. For example, you are in the outdated ID slightly, point your ID will appear a pile of information about you, this is the only identification.
Int (10) is the data type, representing 10-bit integers, unsigned mean, auto_increment is automatically added. Because the ID is set to be automatically added, so we have to build it after the pipe, let it go to its own, hehe.
Name this field to store the name, note that the field name can be arbitrarily named, such as now "name", but in order to facilitate the explanation behind, we temporarily wronged to name it. It is recommended that the naming rules be lowercase letters oh, underlined in the middle can also be. varchar (10) Store Chinese, 10 words should be enough? Oh, whatever, that's it. Varcha R and Char, the former saves space, the latter saves time ... Pull away, these data types, or you Google understand it. Utf8_general_ci, character set, this is very important oh, you must know your own database with what character set, otherwise there will be a pile of garbled oh. Speaking of character sets, I strongly recommend that you use UTF8.
Sex is used to store sex, why is the type tinyint (1) and the 1-bit small integer sufficient? Of course, to imitate the binary system, with 0 for women, with 1 means that the male on the 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 brought it, Mobi used to store cell phone number, of course, 11 bit slightly.
Email is used to store emails, and 50-bit should be more than enough.
Addr used to store the mailing address, the universe, the Earth, the country, the province, the city, township, town, village are written in, 50 should be enough, hehe.
So we're going to create the database now, we recommend that you use phpMyAdmin SQL to import the following statements, because this is the most convenient:
Copy Code code as follows:
CREATE TABLE ' Addr_list ' (
' ID ' int (a) unsigned not NULL auto_increment,
' Name ' varchar 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 manual input can also Oh, if you are not too tired, hehe, but to pay attention to, is that all the ' symbols removed. That's the weird button on the TAB key. Otherwise, there may be an accident.
Well, then we will wait for everyone to finish the database to say it, played a half-day word, hand good acid, belly is also good hungry, hehe. First go to eat, a will continue, there are 4 points on the outdated, hope as soon as possible, so you can screenshots, but the use of characters to draw a table is quite interesting, hehe.
Well, below we will do one of the Web page, one by one to write the program:
The revolution has not yet won ~ Let's go on. Need to add to the above: to create a database before you can import Oh!
To differentiate and facilitate explanations, I name the database list, name the datasheet addr_list, or write out the complete SQL statement.
First create the Database list:
Copy Code code as follows:
CREATE DATABASE ' list ';
Then create the datasheet addr_list:
Copy Code code as follows:
CREATE TABLE ' Addr_list ' (
' ID ' int (a) unsigned not NULL auto_increment,
' Name ' varchar 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 read the full text