2
$sql = "CREATE TABLE comments 
(
ID INT NOT NULL AUTO_INCREMENT,
PosterName VARCHAR(32),
Title VARCHAR(32),
Content VARCHAR(500)
)";
$con->query($sql);

No errors, connection to database is successful. Does anyone know why it doesnt work?

1
  • The $con->query() method would've returned false if there was an error, and you would then need to output $con->error to see the error message. Commented Aug 8, 2013 at 22:09

1 Answer 1

6

You should have seen that error with that statement:

Incorrect table definition; there can be only one auto column and it must be defined as a key:


auto_increment column must have an UNIQUEindex on them, or more generally being the PRIMARY KEY:

$sql = "CREATE TABLE comments 
(
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
PosterName VARCHAR(32),
Title VARCHAR(32),
Content VARCHAR(500)
)";
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I guess that was the problem. Weird how no errors were appearing for me :o Marking as best answer

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.