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’.

mysql-1

Specific requirements of tutorial:

  1. Knowledge of HTML and <form>. If I say ‘make a form’ you should know what to do.
  2. Knowledge of $_POST or $_GET, depending on what you decide to use for the form.
  3. A server with MySQL installed and a database to work with.

(it is assumed that you have all of the requirements specified earlier)

Briefing

  1. 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).
  2. 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.)
  3. On the page with the form, have a short list (10 entries or so) of recent rows that have been added.

Run Through/Hints

  1. 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.
  2. 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!)
  3. 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: , , ,

Like this post? Someone else might, too.

  • RSS
  • Reddit
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Technorati
  • Twitter
  • Digg

Leave a Reply

Subscribe to gulati.info

Subscribe via RSS (?) Subscribe to our RSS feed Subscribe via Email
Follow me on Twitter Follow me on Twitter