Answer the question
In order to leave comments, you need to log in
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
)
Answer the question
In order to leave comments, you need to log in
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`)
)
The dimension for INT is forgotten.
It should be something like this:`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
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.
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`)
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question