0

Alright, for some odd reason, the below syntax is incorrect. I have successfully connected to the database on previous lines, now i'm trying to create a table.
The error I get is:

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 'PRIMARY_KEY, username VARCHAR(255) NOT NULL UNIQUE_KEY, email VARCHAR(255) IND' at line 2

The stranger part is that the query below starts on line 22 and line 2 is blank.

mysql_query("CREATE TABLE users(
	userid INT(11) NOT NULL AUTO_INCREMENT PRIMARY_KEY,
	username VARCHAR(255) NOT NULL UNIQUE_KEY,
	email VARCHAR(255) INDEX,
	password VARCHAR(255),
	role TINYINT(2) UNSIGNED,
	status TINYINT(2) UNSIGNED,
	lastip INT(10) UNSIGNED,
	first_name VARCHAR(255),
	last_name VARCHAR(255)
)") or die('<span style="color:red">Could not create table users in ' . $dbname . ': ' . mysql_error() . '</span><br>');
echo "<span style=\"color:green\">Table has been successfully created!</span><br>";

I have tried just about every kind of troubleshooting and I can't seem to get the error to go away. If you see the error, please let me know.

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by epicrevolt
0

To answer my own question above, here is the solution. I placed PRIMARY_KEY instead of PRIMARY KEY.

mysql_query("CREATE TABLE users(
	userid INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
	username VARCHAR(255) NOT NULL UNIQUE KEY,
	email VARCHAR(255) INDEX,
	password VARCHAR(255),
	role TINYINT(2) UNSIGNED,
	status TINYINT(2) UNSIGNED,
	lastip INT(10) UNSIGNED,
	first_name VARCHAR(255),
	last_name VARCHAR(255)
)") or die('<span style="color:red">Could not create table users in ' . $dbname . ': ' . mysql_error() . '</span><br>');
echo "<span style=\"color:green\">Table has been successfully created!</span><br>";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.