10.1. Tables

The database requirements for this project are rather simple. You need two database tables: one to store the blog posts made by the author and another table to store visitor comments.

+------------+------------------+------+-----+-------------------+----------------+
| Field      | Type             | Null | Key | Default           | Extra          |
+------------+------------------+------+-----+-------------------+----------------+
| POST_ID    | int(10) unsigned | NO   | PRI | NULL              | auto_increment |
| POST_TITLE | varchar(50)      | NO   |     |                   |                |
| POST_TEXT  | text             | NO   |     |                   |                |
| POST_DATE  | timestamp        | NO   |     | CURRENT_TIMESTAMP |                |
+------------+------------------+------+-----+-------------------+----------------+

+--------------+------------------+------+-----+-------------------+
| Field        | Type             | Null | Key | Default           |
+--------------+------------------+------+-----+-------------------+
| POST_ID      | int(10) unsigned | NO   | MUL |                   |
| PERSON_NAME  | varchar(50)      | NO   |     |                   |
| POST_COMMENT | varchar(255)     | NO   |     |                   |
| COMMENT_DATE | timestamp        | NO   |     | CURRENT_TIMESTAMP |
+--------------+------------------+------+-----+-------------------+

If you want to require visitors to register before leaving a comment, you could change PERSON_NAME to reference the USER_ID in some user table and then make the appropriate checks before saving the comment to the database. I simply store their names in a VARCHAR column since I am not planning on requiring my visitors to be site members.

Here is the SQL code for the database tables: ...

Get PHP and MySQL®: Create-Modify-Reuse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.