Đức Hợp Trần Đức Hợp Trần - 1 year ago 69
MySQL Question

MySQL how to set USERNAME field should be designated as UNIQUE

Here is my code in index.php:

$sql = "CREATE TABLE 6470exerciseusers (
USERNAME VARCHAR(100),
'PASSWORD_HASH' CHAR(40),
PHONE VARCHAR(10),
UNIQUE (USERNAME)
)";


and this is the error:


Error creating 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 ''PASSWORD_HASH' CHAR(40), PHONE VARCHAR(10), UNIQUE (USERNAME) )' at line 3

Answer Source
 CREATE TABLE Yourtablename (
USERNAME VARCHAR(100) UNIQUE ,
PASSWORD_HASH CHAR(40),
PHONE VARCHAR(10),
)

There is error in your sql syntax You can make it clear by using the above statement

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download