Making a Trivial Message Board

First we need to make a table in our mysql database. We have named our database abautomatic and our user name is test_teacher. We will create a table with only two fields (we could have just one in theory). One field is the message id and the second field is the actual message content. we limit the content to 50 letters. see this link for a list of options for creating tables:

We will use the AUTO_INCREMENT option in order to automatically increment the message id.
Note: we only made the id field AUTO_INCREMENT.

[root@esp root]# mysql -u test_teacher -p abautomatic Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 82 to server version: 3.23.53a Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create table test(id int NOT NULL AUTO_INCREMENT, message varchar(50), PRIMARY KEY(id)); Query OK, 0 rows affected (0.01 sec) mysql> explain test; +---------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | message | varchar(50) | YES | | NULL | | +---------+-------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec) mysql> exit Bye [root@esp root]# Then we make a php page called message.php which looks like this: <html> <heAD> <title>Trivial Message Board</title></head> <body> <?php $link = mysql_connect('localhost', 'test_teacher', '58839870'); mysql_select_db('abautomatic') or die("Failed DB Select"); if (isset($HTTP_POST_VARS['message']))// use built-in isset to check if the user is currently passing the variable "message" { $query = "INSERT INTO test SET message='".$HTTP_POST_VARS['message']."'"; mysql_query($query) or die("Failed Query: $query"); //run the above query } else if (isset($HTTP_POST_VARS['clean'])) { $query = "DELETE FROM test"; mysql_query($query) or die("Failed Query: $query"); //run the above query } $query = "SELECT * FROM test";//get all data $result = mysql_query($query) or die("Failed Query: $query"); //run the above query //print results in table format print "<table> <caption>Trivial Message Board </caption>"; print "<tr><td>message number</td><td>message content</td></tr>"; while($row = mysql_fetch_array($result)) { print "<tr><td>".$row['id']."</td><td>".$row['message']."</td></tr>"; } print "</table>"; ?> <form method="POST" action="message.php"> ADD MESSAGE: <input type="text" maxlength="50" name="message"> <input type="submit"> </form> <form method="POST" action="message.php"> <input type="hidden" maxlength="50" name="clean"> <input type="submit" value="Clear All Data"> </form> </body> </html> Here is the location of the above page: