-1

I'm encountering this error when trying to load a .sql file to PHPMyAdmin:

Error Message

Here is what the .sql code looks like:

CREATE TABLE IF NOT EXISTS `category` (
    `category_id` int(11) NOT NULL AUTO_INCREMENT,
    `category_name` varchar(255) NOT NULL,


CREATE TABLE IF NOT EXISTS `product` (
    `product_id` int(11) NOT NULL AUTO_INCREMENT,
    `category_id` int(11) NOT NULL,
    `product_name` varchar(250) NOT NULL,
    `product_image` varchar(250) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
Dharman
  • 30,962
  • 25
  • 85
  • 135
R.Todd
  • 1
  • 5
  • Your actual error is that the `category` table isn't properly defined. Missing some columns and the closing bracket. – Qirel May 05 '17 at 23:57
  • Notice how it complained "hear" `CREATE` of `product`. Then either the `CREATE` is "wrong", or the thing immediately before it (a comma) is "wrong". – Rick James May 06 '17 at 16:54

2 Answers2

1

When creating the category table, you are not closing the parentheses that you opened. Your statement:

CREATE TABLE IF NOT EXISTS 'category' (
    'category_id' int(11) NOT NULL AUTO_INCREMENT,
    'category_name' varchar(255) NOT NULL,

needs to be closed with a );

You also need to remove the trailing comma ,.

Daniel Arthur
  • 456
  • 7
  • 17
  • @arieljannai I understand these are likely basic concerns... But this is how I learn... My questions are actually code related questions... – R.Todd May 13 '17 at 02:42
  • And I don't understand #1046 - No database selected... The database does exist, and so do the tables... – R.Todd May 13 '17 at 03:05
1

You're missing the closing brackets of your queries (perhaps some more columns, you'll see it after you fix the brackets)

arieljannai
  • 2,124
  • 3
  • 19
  • 39
  • And I fixed the brackets and I get... CREATE TABLE IF NOT EXISTS `category` ( `category_id` int(11) NOT NULL AUTO_INCREMENT, – R.Todd May 13 '17 at 02:45
  • And I'm using pictures because it's more visual... and I am trying to work with a .sql file... – R.Todd May 13 '17 at 02:45
  • tables 'category' and 'product' are actually created in the DB... How do I add to it... – R.Todd May 13 '17 at 02:52