9.3 Adding user data to a database: PHP and MySQL

Now we are all set to add the data to a database.  Since this class is not set up to go over databases or server side scripting, we will just go over some of the basic concepts here.  First, we will be using a database called “MySQL” which comes with the tagline, “the world’s most popular open source database”.  MySQL is included in most web-hosting packages.  This tutorial will also assume that a database administrator has received your request for a database, and has create a table for you as well.  The following is a screenshot of the database table generated for this tutorial:

 

The table has just 6 fields:

  1. id (primary key)
  2. lat
  3. lon
  4. name
  5. description
  6. category

Our previous tutorial took the values from the input form, packaged it into an object (data), and sent it to a PHP file called “adddata.php”.  Let’s create this file.  In the same directory, add a new file in the same directory, and call is “adddata.php”.  Paste the following PHP code:

Leave a Reply