Whenever I go to sql in phpmyadmin to create a table, I put this code in:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`sign_up_date` date NOT NULL,
`activated` enum('0','1') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
it says:#1046 - No database selected
but when I put:
CREATE DATABASE data;
USE data;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`sign_up_date` date NOT NULL,
`activated` enum('0','1') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
it says that it could not create the database?
Since you have got your sql statement, then just go to phpMyAdmin > login (if there is need for it) > select database you want to use, find it in Right Hand Side , example 'test'. tehn simply just find the tab named sql and click it, after that just paste your statements
One server can contain multiple databases. If you login into PHPMyAdmin, you choose a server to login to. After you've logged in, you have to select your database to be able to make changes to it.
So you don't need to create a database. You just need to select it. You can do that with the
USE <databasename>
statement, or though the PHPMyAdmin interface. In your second snippet, you already used have theUSE
statement. You just need to remove theCREATE DATABASE
statement.Same goes for creating the table, by the way. PHPMyAdmin provides an interface to add a table field by field without having to write the SQL for it. Although it can't hurt to know the syntax, of course.
Step 1: Choose an existing Database or create a new Database.
Step 2: Choose the SQL tab and add your code to create a table.