A
A
AVXNWNK2015-11-02 21:06:26
MySQL
AVXNWNK, 2015-11-02 21:06:26

What is causing the SQL query to the database to fail?

In general, the problem is this: a text SQL query is not executed in the database to create a table with fields. This error was first reported via mysql_error(); on php, but then having tried to make a request in phpMyAdmin, I realized that the error was not in the php code.
Request:

CREATE TABLE IF NOT EXISTS `entries` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`stamp` TIMESTAMP NOT NULL,
`name` CHAR(30) CHARACTER SET utf8 NOT NULL,
`desc` TEXT CHARACTER SET utf8 NOT NULL,
`creator` CHAR(30) CHARACTER SET utf8 NOT NULL,
`price` INT(10) NOT NULL,
`weight` REAL(10) NOT NULL,
`material` CHAR(30) CHARACTER SET utf8 NOT NULL,
`made` CHAR(30) CHARACTER SET utf8 NOT NULL,
`size` REAL(10) NOT NULL,
`condition` CHAR(30) NOT NULL
)

Mistake:
870dc8092c7c4502a3795cba4ee75932.png

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Ruslan Fedoseev, 2015-11-02
@AVXNWNK

CREATE TABLE IF NOT EXISTS `entries` (
`id` INT NOT NULL AUTO_INCREMENT,
`stamp` TIMESTAMP NOT NULL,
`name` CHAR(30) CHARACTER SET utf8 NOT NULL,
`desc` TEXT CHARACTER SET utf8 NOT NULL,
`creator` CHAR(30) CHARACTER SET utf8 NOT NULL,
`price` INT(10) NOT NULL,
`weight` REAL(10,4) NOT NULL,
`material` CHAR(30) CHARACTER SET utf8 NOT NULL,
`made` CHAR( 30) CHARACTER SET utf8 NOT NULL,
`size` REAL(10,4) NOT NULL,
`condition` CHAR(30) NOT NULL,
PRIMARY KEY (`id`)
)

I
Immortal_pony, 2015-11-02
@Immortal_pony

The dimension for INT is forgotten.
It should be something like this:
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,

A
Adamos, 2015-11-02
@Adamos

REAL is described not by one size, but by two - how many digits in total and digits after the dot.
REAL(10,2) - for example.
Actually, for prices, it is more logical to use the DECIMAL created specifically for them. with the same description.

A
AVXNWNK, 2015-11-02
@AVXNWNK

The request was made with the following code:

CREATE TABLE IF NOT EXISTS `entries` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`stamp` TIMESTAMP NOT NULL,
`name` CHAR(30) CHARACTER SET utf8 NOT NULL,
`desc` TEXT CHARACTER SET utf8 NOT NULL,
`creator` CHAR(30) CHARACTER SET utf8 NOT NULL,
`price` INT(10) NOT NULL,
`weight` REAL(5,2) NOT NULL,
`material` CHAR(30) CHARACTER SET utf8 NOT NULL,
`made` CHAR(30) CHARACTER SET utf8 NOT NULL,
`size` REAL(5,2) NOT NULL,
`condition` CHAR(30) NOT NULL,
PRIMARY KEY (`id`)
)

Thanks to all!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question