Morina Tutorials: PHP & MySQL

Create a MYSQL Database Table with phpMyAdmin

PHP MyAdmin is installed on all our UNIX hosting packages. The prices start at only 9.99 euro per month, for 300 GB disk space and 3000 GB traffic. Please, feel free to contact us for details and/or a free quote.

In this example I will show you how to create a simple table named my_quotes and insert new records in a MySQL database, using PHP MyAdmin.

quote_id quote auth_fn auth_mn auth_ln subject
1 I am beginning to suspect all elaborate and special systems of education. They seem to me to be built up on the supposition that every child is a kind of idiot who must be taught to think. Anne   Sullivan education
2 Creativity is a type of learning process where the teacher and pupil are located in the same individual. Arthur   Koestler education
3 Education is a better safeguard of liberty than a standing army. Edward   Everett education
4 Education is what remains after one has forgotten everything he learned in school. Albert   Einstein education
  1. quote_id: quote identification, a unique key
  2. quote: content of the quote
  3. auth_fn: author's first name
  4. auth_mn: author's middle name
  5. auth_ln: author's last name
  6. subject

1. Open phpMyAdim and enter your username and password to login:

2. Click on Databases

3. Click on the name of your database where you want to create a table.

4. Click on Operations

5. Enter the table name and number of fields, and click Go

6. Define field properties and click Go

Explanation:

quote_id is an integer (maximum value: 2147483647), the value cannot be empty (not null), a number is assigned and increased automatically each time a new record is inserted into the table (auto_increment)

quote contains text (maximum length of 65535 characters, ~ 64kb); other values for text are mediumtext (~ 16 MB) and bigtext (4 GB)

varchar can contain 0 to 255 characters: I assigned 100 characters to this field and I want to allow the field value to be empty (null)

 

The result of the created table

Creating a new table with an SQL command

An easier way to create a table is using an SQL command. After logging in, select the database and click on the SQL tab, type the command and click Go. The SQL query for the table as in the example above is:

CREATE TABLE IF NOT EXISTS `my_quotes` (
`quote_id` int(11) NOT NULL auto_increment,
`quote` text,
`auth_fn` varchar(100) default NULL,
`auth_mn` varchar(100) default NULL,
`auth_ln` varchar(100) default NULL,
`subject` varchar(100) default NULL,
PRIMARY KEY (`quote_id`)
) TYPE=MyISAM;

Inserting records in the table

To insert new records click on the tab insert and fill in the content for each field. In this demonstration the id (quote_id) is assigned automatically.

Another, more practical, method is by typing an SQL query:

INSERT INTO `my_quotes` (`quote_id`, `quote`, `auth_fn`, `auth_mn`, `auth_ln`, `subject`) VALUES
('', 'I am beginning to suspect all elaborate and special systems of education. They seem to me to be built up on the supposition that every child is a kind of idiot who must be taught to think.', 'Anne', '', 'Sullivan', 'education'),
('', 'Creativity is a type of learning process where the teacher and pupil are located in the same individual.', 'Arthur', '', 'Koestler', 'education'),
('', 'Education is a better safeguard of liberty than a standing army.', 'Edward', '', 'Everett', 'education'),
('', 'Education is what remains after one has forgotten everything he learned in school.', 'Albert', '', 'Einstein', 'education');
PHP Tutorials
Other Tutorials