1

Following is my SQL query:

Attempt 1

INSERT INTO `product`(`productid`, `title`, `category`, `description`) 
VALUES (NULL,`iMac`,`Desktop`,`With its enhanced, big and beautiful display, the new Apple iMac M-D093-B/A 21.5 Desktop Computer renders your movies, photos, web pages and other graphics in truly jaw-dropping detail.`)

Attempt 2

INSERT INTO `product`(`productid`, `title`, `category`, `description`) 
VALUES(` `,`iMac`,`Desktop`,`With its enhanced, big and beautiful display, the new Apple iMac M-D093-B/A 21.5 Desktop Computer renders your movies, photos, web pages and other graphics in truly jaw-dropping detail.`)

I keep getting an error of : MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0003 sec )

I don't understand what am i doing wrong. Here is my column name list

1  productid int(11)    
2  title varchar(100)
3  category varchar(100)
4  description varchar(2000) 

table name:product

Andy
  • 14,260
  • 4
  • 43
  • 56
kiran patel
  • 135
  • 1
  • 3
  • 10

2 Answers2

4

For the values, use the ' character, not this one: ``` (sorry, I'll have to find out how to put a single backtick into an inline code block in Markdown...)

INSERT INTO `product`(`productid`, `title`, `category`, `description`) 
VALUES (NULL,'iMac','Desktop','With its enhanced, big and beautiful display, the new Apple iMac M-D093-B/A 21.5 Desktop Computer renders your movies, photos, web pages and other graphics in truly jaw-dropping detail.')

And this should work... Here is the SQLfiddle for it.

EDIT This is the solution as per zour table definition:

INSERT INTO `product`(`title`, `category`, `description`) 
VALUES ('iMac','Desktop','With its enhanced, big and beautiful display, the new Apple iMac M-D093-B/A 21.5 Desktop Computer renders your movies, photos, web pages and other graphics in truly jaw-dropping detail.')

You had two things you forgot to mention: * productid is a PRIMARY KEY (and hence, automatically NOT NULL) column -- any inserts with a NULL in that column will fail * productid is an AUTO_INCREMENT column -- you don't even have to include it in the INSERT statement, it will get filled with an unique value each time you insert a row

The SQL fiddle for this

ppeterka
  • 20,583
  • 6
  • 63
  • 78
  • I believe the pattern for an inline backtick is backtick,backslash,backtick,backtick... `\`` – Michael Berkowski Feb 28 '13 at 14:16
  • @MichaelBerkowski Thanks a lot, I was just about to try the good old escaping. EDIT: it works in a comment, but doesn't work in an answer?(I get 3 backticks...) – ppeterka Feb 28 '13 at 14:17
  • Hmm, it worked in my comment but not when I tried to edit your answer.. That might be a bug. I'm going to check meta. – Michael Berkowski Feb 28 '13 at 14:17
  • Thank you but it doesn't work. Is inserting data through Sql query affected by the version you are using?i am new to this so i really don't know how to solve this problem. – kiran patel Feb 28 '13 at 14:21
  • @kiranpatel please post your table definition (CREATE TABLE statement) to be sure. Is it not that the `productid` column is a `PRIMARY KEY`? Or at least not null? – ppeterka Feb 28 '13 at 14:27
  • CREATE TABLE `product` ( `productid` int( 11 ) NOT NULL AUTO_INCREMENT , `title` varchar( 100 ) NOT NULL , `category` varchar( 100 ) NOT NULL , `description` longtext NOT NULL , PRIMARY KEY ( `productid` ) ) ENGINE = MYISAM DEFAULT CHARSET = latin1; – kiran patel Feb 28 '13 at 14:29
  • @ ppeterka your solution was correct. i had error when i pasted your answer but then i retyped the solution(query) and it worked! i'm really greatful to you for helping me to solve the problem. thank you very much.:) – kiran patel Feb 28 '13 at 21:13
0

You have to use ' with every varchar, datatype, so in your case:

INSERT INTO product(productid, title, category, description) VALUES 
(
    NULL,
    'iMac',
    'Desktop', 
    'With its enhanced, big and beautiful display, the new Apple iMac M-D093-B/A 21.5 Desktop Computer renders your movies, photos, web pages and other graphics in truly jaw-dropping detail.'
);
Ullas
  • 11,450
  • 4
  • 33
  • 50
puchmu
  • 109
  • 11
  • Thank you for your quick response But this query also get the same error.:( (MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0004 sec ) – kiran patel Feb 28 '13 at 14:17
  • is productid your primary key? if yes, this must not be NULL – puchmu Feb 28 '13 at 14:20
  • yes it is. i thought since i have added as Auto Increment, it would upload a digit byitself, woudn't it? – kiran patel Feb 28 '13 at 14:25
  • does it work when you change NULL to any number? – puchmu Feb 28 '13 at 14:28
  • Post your create table statement, and all your queries so that we can find the error – puchmu Feb 28 '13 at 14:44
  • CREATE TABLE `product` ( `productid` int( 11 ) NOT NULL AUTO_INCREMENT , `title` varchar( 100 ) NOT NULL , `category` varchar( 100 ) NOT NULL , `description` longtext NOT NULL , PRIMARY KEY ( `productid` ) ) ENGINE = MYISAM DEFAULT CHARSET = latin1; thts the table it's not working. please i really need help. – kiran patel Feb 28 '13 at 14:53
  • I tried my solution in phpmyadmin and it works just fine with your create table statement and my query. I think the problem is somewhere else. Have you tried other queries on other tables? try SELECT UPPER('foo') FROM DUAL; to find out if your database works. – puchmu Feb 28 '13 at 15:48
  • thank you for your suggestion i got the answer. the problem was the use of backtick and single quotes plus the primary key in table. i really appreciate your help.:) – kiran patel Feb 28 '13 at 21:09