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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.