Briefing: Using MySQL
posted on August 16, 2009
This tutorial will teach you the basics of using MySQL with PHP. It will prepare you for the next tutorial, ‘Creating a Simple Login System’.

Specific requirements of tutorial:
- Knowledge of HTML and <form>. If I say ‘make a form’ you should know what to do.
- Knowledge of $_POST or $_GET, depending on what you decide to use for the form.
- A server with MySQL installed and a database to work with.
(it is assumed that you have all of the requirements specified earlier)
Briefing
- Set up a table. You can name it whatever you want. It should have the fields: ‘body’ (TEXT), ‘time’ (INT 12), and ‘ip_address’ (VARCHAR 16).
- Create a single input. When submitted, it should add a row in the database (the value of input is ‘body’, time is the timestamp, and ip_address is the user’s IP address.)
- On the page with the form, have a short list (10 entries or so) of recent rows that have been added.
Run Through/Hints
- It’s much easier to use a tool like phpMyAdmin to create the table. If that isn’t available, you should be able to find some information on using the
mysql>prompt to create a table. - Take things in order. Here’s a brief run through of what you need to do:
- Write the code to connect to the MySQL server
- Write the code to select the MySQL database
- Create the form
- Write the code to add rows to the database when the form is submitted (be sure to clean the input here!
mysql_real_escape_string()is important!)
- This is a simple addition to the second task. You should output the body and format the timestamp with
date().
The solution will probably be released tomorrow. Good luck! :)
Tags: Learn MySQL, Learn PHP, PHP and MySQL, Using MySQL









