Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Using PHP with MySQL Using Relationship Tables in MySQL Understanding Relationship Tables

Tong Vang
Tong Vang
9,926 Points

ERROR importing sizes table into xampp MySQL

Error

SQL query:

CREATE TABLE sizes ( id int(11) NOT NULL AUTO_INCREMENT, size varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL, order int(11) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5 ;

MySQL said: Documentation

1046 - No database selected

I got the above error when I copied and pasted the downlowned sql file. What is wrong. I noticed the file did not have the "USE" line. But when I inserted it in, I still got the same error. Below is the create part of the database:

CREATE TABLE sizes ( id int(11) NOT NULL AUTO_INCREMENT, size varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL, order int(11) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5 ;

5 Answers

Gareth Borcherds
Gareth Borcherds
9,372 Points

I think you're confusing database from tables. A database is the collection of tables. In phpmyadmin you need to enter the database and then run the query. So when you start up the phpmyadmin, select the database tab, then select a database from the list, then once you've done that, you can run your query.

Gareth Borcherds
Gareth Borcherds
9,372 Points

What this means is that you are trying to create a table without actually creating a database. You have to create a database first, then from that database you can run the sql create statement to create the table.

Tong Vang
Tong Vang
9,926 Points

I do have a database. I copied and pasted the database on to MyphpAdmin just like Hoyt instruct\ed to do. Do I need to put the new database in the same folder as the first on my hard drive also?.

Tong Vang
Tong Vang
9,926 Points
CREATE TABLE `sizes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `size` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
  `order` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5 ;


INSERT INTO `sizes` (`id`, `size`, `order`) VALUES(1, 'Small', 10);
INSERT INTO `sizes` (`id`, `size`, `order`) VALUES(2, 'Medium', 20);
INSERT INTO `sizes` (`id`, `size`, `order`) VALUES(3, 'Large', 30);
INSERT INTO `sizes` (`id`, `size`, `order`) VALUES(4, 'X-Large', 40);

CREATE TABLE `products_sizes` (
  `product_sku` int(11) NOT NULL,
  `size_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(101, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(101, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(101, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(101, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(102, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(102, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(102, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(102, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(103, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(103, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(103, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(103, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(104, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(104, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(104, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(104, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(105, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(105, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(105, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(105, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(106, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(106, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(106, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(106, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(107, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(107, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(107, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(107, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(108, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(108, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(108, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(108, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(109, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(109, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(109, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(109, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(110, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(110, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(110, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(110, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(111, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(111, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(111, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(111, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(112, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(112, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(112, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(112, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(113, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(113, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(113, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(113, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(114, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(114, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(114, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(114, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(115, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(115, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(115, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(115, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(116, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(116, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(116, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(116, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(117, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(117, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(117, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(117, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(118, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(118, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(118, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(118, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(119, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(119, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(119, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(119, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(120, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(120, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(120, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(120, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(121, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(121, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(121, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(121, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(122, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(122, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(122, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(122, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(123, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(123, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(123, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(123, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(124, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(124, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(124, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(124, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(125, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(125, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(125, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(125, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(126, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(126, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(126, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(126, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(127, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(127, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(127, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(127, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(128, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(128, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(128, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(128, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(129, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(129, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(129, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(129, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(130, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(130, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(130, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(130, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(131, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(131, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(131, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(131, 4);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(132, 1);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(132, 2);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(132, 3);
INSERT INTO `products_sizes` (`product_sku`, `size_id`) VALUES(132, 4);

This is the database.

Tong Vang
Tong Vang
9,926 Points

You are right. Randy went too fast and I missed the first step in creating the table. It looked similar to creating a database. I used the wrong window. Like you said I needed to select the database first before pasting the table creation instructions. Thanks.