I am trying to create this table in my php file:
mysql_query("CREATE TABLE Orders (orderID INT(3) NOT NULL PRIMARY KEY AUTO_INCREMENT,
FOREIGN KEY (userID) REFERENCES Users (userID))");
However, whenever this query runs it doesn’t create the table.
Am I creating the foreign key wrong?
Echo result of
mysql_error()after the query and you will see why the query is failing.In your case, there is no column
userID, and you are trying to create a foreign key on that column. You have to define the column first. Make sure it has exact the same data type as inUserstable