0

$createtable=mysql_query("CREATE TABLE IF NOT EXISTS users(username VARCHAR(20),password VARCHAR(20),read TINYINT(1),write TINYINT(1),search TINYINT(1))");

I get the following error when trying to create the table using the above query: Error creating user table: 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 'read TINYINT(1),write TINYINT(1),search TINYINT(1))' at line 1

how do i successfully create the table?thanks in advance.

1
  • 2
    read is a mysql reserved word, so you'd need to wrap it in backticks to get it working (ditto for write). You should look at changing the field names if at all possible instead. Commented Jun 19, 2013 at 17:50

2 Answers 2

1

try this

 $createtable=mysql_query("CREATE TABLE IF NOT EXISTS users(username VARCHAR(20),password VARCHAR(20),`read` TINYINT(1),`write` TINYINT(1),search TINYINT(1))");

you have read and write are mysql reserved keywords , so you should around them by backticks

Sign up to request clarification or add additional context in comments.

Comments

0

Try:

$createtable=mysql_query("CREATE TABLE IF NOT EXISTS users(`username` VARCHAR(20),`password` VARCHAR(20),`read` TINYINT(1),`write` TINYINT(1),`search` TINYINT(1))");

2 Comments

While this will work, it's generally bad practice to use reserved words as column names.
should be write reserved-words

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.