Jump to content
xisto Community
alex1985

Sql Query Mistake?

Recommended Posts

Hi, everyone! What is the mistake over here?

'id' INT(11) NOT NULL AUTO_INCREMENT,
'username' VARCHAR(255) NOT NULL,
'password' VARCHAR(255) NOT NULL,
PRIMARY KEY ('id')
) TYPE MYISAM; linenums:0'>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:

#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?

Share this post


Link to post
Share on other sites

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

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;

Share this post


Link to post
Share on other sites

Sorry, but the PHPMyAdmin still gives the following:

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


Share this post


Link to post
Share on other sites

OK, try the following:

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:

CREATE TABLE `databasename`.`1_users` (

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Thats odd... I've never known that before. I've sometimes used ` but usually I use ' and they both seem to run fine on sql. Are you sure about this?

Share this post


Link to post
Share on other sites

Thats odd... I've never known that before. I've sometimes used ` but usually I use ' and they both seem to run fine on sql. Are you sure about this?

I've found that sometimes it makes a difference. If I remember correctly, the difference is something similar to single quotes and double quotes in PHP. If you use a single quote in SQL, then whatever is between the single quotes will be parsed. If you use backticks (that's the ` character) then it is not parsed. This allows you to use words like INT in column names, which would otherwise be parsed by MySQL, throwing up an error as it would make no sense.

Share this post


Link to post
Share on other sites

I found one tutorial how to make a complete login system which suggest to use the following SQL syntax to encrypt the password:

INSERT INTO login (username,password,email,activated) value ('admin',sha1(concat('yourpasswordhere','0dAfghRqSTgx')),'youremailhere','1');

Is it appropriate or not?!

Share this post


Link to post
Share on other sites

Looks good to me. Try it on a test database and let us know if it works.What it is saying is to Insert into this table, the list of fields listed inside the first round brackets, the list of values found in the second set of round brackets. The list of fields and their values should be in the same order.The 'password' will be an encrypted value of the concatenated literal password and a 'salt'. This is more secure than simply encrypting the password by itself, but the same 'salt' should be used when you compare any passwords they use on log-in, so it needs to be stored someplace.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.