ryan.od Posted September 24, 2006 Share Posted September 24, 2006 Can anyone tell me what is wrong with this? The reviews_post table and the reviews_post_category table generate an error and I don't know why.Also, the post -> category relationship is many-to-many. As such, I created the reviews_post_category table that only has foreign keys in it that reference the post ID and the category ID in their respective tables. Is this the correct approach?Thanks,Ryan<?phprequire_once('db_connect.php');mysql_select_db ('evaluati_reviews');$sql = 'CREATE TABLE reviews_author( id_author int(11) NOT NULL auto_increment, fname_author varchar(30) NOT NULL, lname_author varchar(50) NOT NULL, PRIMARY KEY (id_author),)';$result = mysql_query($sql) or print ("Can't create the table 'reviews_author' in the database.<br />" . $sql . "<br />" . mysql_error());if ($result != false) { echo('Article database created successfully!'); }$sql = 'CREATE TABLE reviews_date( id_date int(11) NOT NULL auto_increment, date_date timestamp(8) NOT NULL, PRIMARY KEY (id_date),)';$result = mysql_query($sql) or print ("Can't create the table 'reviews_date' in the database.<br />" . $sql . "<br />" . mysql_error());if ($result != false) { echo('Article database created successfully!'); }$sql = 'CREATE TABLE reviews_category( id_category int(11) NOT NULL auto_increment, cat_category varchar(40) NOT NULL, PRIMARY KEY (id_category),)';$result = mysql_query($sql) or print ("Can't create the table 'reviews_category' in the database.<br />" . $sql . "<br />" . mysql_error());if ($result != false) { echo('Article database created successfully!'); }$sql = 'CREATE TABLE reviews_post( id_post int(11) NOT NULL auto_increment, idpost_date int(11), idpost_author int(11), title_post varchar(100) NOT NULL, intro_post varchar(200) NOT NULL, text_post text NOT NULL, PRIMARY KEY (id_post), FOREIGN KEY idpost_date REFERENCES reviews_date(id_date), FOREIGN KEY idpost_author REFERENCES reviews_author(id_author))';$result = mysql_query($sql) or print ("Can't create the table 'reviews_post' in the database.<br />" . $sql . "<br />" . mysql_error());if ($result != false) { echo('Article database created successfully!'); } $sql = 'CREATE TABLE reviews_post_category( id_post int(11), id_category int(11), PRIMARY KEY (id_post, id_category), FOREIGN KEY id_post REFERENCES reviews_post(id_post), FOREIGN KEY id_category REFERENCES reviews_category(id_category),)';$result = mysql_query($sql) or print ("Can't create the table 'reviews_post_category' in the database.<br />" . $sql . "<br />" . mysql_error());if ($result != false) { echo('Article database created successfully!'); }$sql = 'CREATE TABLE reviews_link( id_link int(11) NOT NULL auto_increment, url_link varchar(150) NOT NULL, PRIMARY KEY (id_link),)';$result = mysql_query($sql) or print ("Can't create the table 'reviews_link' in the database.<br />" . $sql . "<br />" . mysql_error());if ($result != false) { echo('Article database created successfully!'); }?> Quote Link to comment Share on other sites More sharing options...
ryan.od Posted September 24, 2006 Author Share Posted September 24, 2006 Nevermind. The problem was that I didn't enclose my FOREIGN KEYS in paranthesis. Duh. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 25, 2006 Share Posted September 25, 2006 Plus, AFAIK, you can't have a trailing comma. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.