Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Sql Query, Mistake?
alex1985
post Mar 8 2008, 12:11 PM
Post #1


Super Member
*********

Group: [HOSTED]
Posts: 397
Joined: 9-February 08
Member No.: 57,615



Hi, everyone! What is the mistake over here?

CODE
CREATE TABLE '1_users' (
'id' INT(11) NOT NULL AUTO_INCREMENT,
'username' VARCHAR(255) NOT NULL,
'password' VARCHAR(255) NOT NULL,
PRIMARY KEY ('id')
) TYPE MYISAM;


The PHPMyAdmin states:

QUOTE
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1_users' (
'id' INT(11) NOT NULL AUTO_INCREMENT,
'username' VARCHAR(255) NOT ' at line 1


Please, let me know as soon as possible?
Go to the top of the page
 
+Quote Post
rvalkass
post Mar 8 2008, 12:56 PM
Post #2


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,153
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol



This is a simple case of the wrong quotes. You need to use ` rather than '. The following should work:

SQL
CREATE TABLE `1_users` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(255) NOT NULL,
`password` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`)
) TYPE MYISAM;
Go to the top of the page
 
+Quote Post
alex1985
post Mar 8 2008, 01:27 PM
Post #3


Super Member
*********

Group: [HOSTED]
Posts: 397
Joined: 9-February 08
Member No.: 57,615



Oh, so easy!!! Thanks for answering, it's good to learn through your forum, replies got answered so fast.
Go to the top of the page
 
+Quote Post
alex1985
post Mar 8 2008, 01:32 PM
Post #4


Super Member
*********

Group: [HOSTED]
Posts: 397
Joined: 9-February 08
Member No.: 57,615



Sorry, but the PHPMyAdmin still gives the following:

QUOTE
SQL query:

CREATE TABLE `users` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ;

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2
Go to the top of the page
 
+Quote Post
rvalkass
post Mar 8 2008, 02:13 PM
Post #5


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,153
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol



OK, try the following:

SQL
CREATE TABLE `1_users` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 255 ) NOT NULL ,
`password` VARCHAR( 255 ) NOT NULL
) ENGINE = MYISAM


If that doesn't work, add the database name before the table name, so the first line would become:
SQL
CREATE TABLE `databasename`.`1_users` (
Go to the top of the page
 
+Quote Post
alex1985
post Mar 8 2008, 02:24 PM
Post #6


Super Member
*********

Group: [HOSTED]
Posts: 397
Joined: 9-February 08
Member No.: 57,615



So, I need to make spaces between words and brackets?! Correct me, I I'm being wrong!
Go to the top of the page
 
+Quote Post
rvalkass
post Mar 8 2008, 02:36 PM
Post #7


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,153
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol



Well, I just ran that code on my own MySQL installation and it worked perfectly. I have found in the past that it can be a little picky about what it lets through and what it doesn't.

If that code still doesn't work, use phpMyAdmin to create the table, and copy the MySQL query it actually runs (it will be displayed to you after the table is created). Then you can be certain that code will work.
Go to the top of the page
 
+Quote Post
alex1985
post Mar 8 2008, 02:45 PM
Post #8


Super Member
*********

Group: [HOSTED]
Posts: 397
Joined: 9-February 08
Member No.: 57,615



QUOTE(rvalkass @ Mar 8 2008, 06:36 PM) *
Well, I just ran that code on my own MySQL installation and it worked perfectly. I have found in the past that it can be a little picky about what it lets through and what it doesn't.

If that code still doesn't work, use phpMyAdmin to create the table, and copy the MySQL query it actually runs (it will be displayed to you after the table is created). Then you can be certain that code will work.


What's about my previous question?
Go to the top of the page
 
+Quote Post
truefusion
post Mar 8 2008, 04:25 PM
Post #9


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,917
Joined: 22-June 05
From: The World of Gentoo
Member No.: 8,528



QUOTE(alex1985 @ Mar 8 2008, 09:24 AM) *
So, I need to make spaces between words and brackets?

Spaces (and new lines) are optional. It should work so long as you follow the syntax, like the error says. SQL query parse errors can be annoying.