MySQL - PHP code problem - I think

Hello…
I am not sure if this is the correct place to post this… I am creating a blog, and I have two databases - one is the manager and contains the manager table and the other is blog database which stores each thread in a different table…

So when a user enters a new post, it enters the details - post name, author, date etc., and then using mysql_inser_id(), I get the previous id as $last_id and then create a new table called $last_id i.e. the value of the last id and put in the other details…

Somehow, I am not able to create this, although the entries are getting registered in the manager table…
Here’s the code for create table:

[php]
mysql_query(“CREATE TABLE $last_id (‘id’ INT NOT NULL AUTO_INCREMENT PRIMARY KEY, ‘author’ VARCHAR(100) NOT NULL, ‘text’ TEXT NOT NULL, ‘email’ TEXT NOT NULL, ‘ip’ TEXT NOT NULL, ‘date’ DATE NOT NULL, ‘website’ TEXT) ENGINE = MyISAM;”) or die(“Cannot create post. Database error!”);
[/php]

Thanks in advance for your help

are you really trying to store each post in a new table?

rather then storing each post in its own table store all the posts in a single table otherwise your going to end up with a lot of tables, its really not a good way of doing things.

Have a users table which will store all the managers info and a posts table which will store all the posts, in the posts table store the user id for each post so you can link a post to it’s author.

THanks for the reply…

I get what u’re saying… but how would you implement it… the id’s can be matched between the tables, but what will the primary_id be for the posts table?

I implemented this pattern because it was the simplest, but I am open to changes…

Thanks again…

okay you’ll need to create 2 tables users and posts you may have more fields in the tables but I’m going to keep it simple for this.

Here’s what I would do for the tables:

mysql_query("CREATE TABLE IF NOT EXISTS `users` (
  `userID` int(11) NOT NULL auto_increment,
  `username` varchar(255) NOT NULL,
  `password` varchar(32) NOT NULL,
  PRIMARY KEY  (`userID`)
) ENGINE=MyISAM");

mysql_query("CREATE TABLE IF NOT EXISTS `posts` (
  `postID` int(11) NOT NULL auto_increment,
  `postTitle` varchar(255) NOT NULL,
  `postCont` text NOT NULL,
  `postDate` date NOT NULL,
  `userID` int NOT NULL,
  PRIMARY KEY  (`postID`)
) ENGINE=MyISAM");

when adding a post store the userID in the posts table to form a relationship between the user and the post.

Sponsor our Newsletter | Privacy Policy | Terms of Service