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!'); }?> Link to comment https://forums.phpfreaks.com/topic/21887-help-creating-tables/ 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. Link to comment https://forums.phpfreaks.com/topic/21887-help-creating-tables/#findComment-97825 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. Link to comment https://forums.phpfreaks.com/topic/21887-help-creating-tables/#findComment-97942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.