Wednesday, 16 November 2016
mysql - SQL query on PHPMyAdmin to insert data not working
Answer
Answer
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
Answer
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
c++ - Does curly brackets matter for empty constructor?
Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...
-
A fair amount of the second act of The Dark Knight Rises has a class warfare plotline. This is foreshadowed in the trailers with Selina Ky...
-
I want to create an options array from a string. How can i create an array as { width : 100, height : 200 } from a string ...
-
There is an episode of the very popular TV series Friends wherein Phoebe says that she wants to patch things up with her twin sister before ...
No comments:
Post a Comment