Jump to content

Help creating tables??


ryan.od

Recommended Posts

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

<?php

require_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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.