Information Structure and Retrieval: WeekSeven

Wiki Controls

Quick Links

Notes and Activities for Week Seven (October 9)





phpMyAdmin


phpMyAdmin is a PHP-based utility that allows more or less graphical control of MySQL databases. In many respects, it's straightforward--if you understand a few basic concepts about how MySQL databases are constructed.

In MySQL, a database is an organizing scheme for numerous tables, which contain columns for different types of data, and rows that constitute a single record, made up of the items in each column.

You must name your databases, tables, and columns (and columns themselves must be specified as having a particular type of data). And while there is a fairly wide range of allowable names of these different types of objects (databases, tables, columns), there are certain reserved words that you would be wise to avoid.

Just like with XML tags, MySQL objects should generally be named in a self-describing fashion. A database running your blog might be called blog or myblog or johnsblog--and part of that will depend on the context of the database's use.

And also, just like XML tags, MySQL allows upper- and lowercase letters, as well as numbers and certain punctuation (like the underscore). Again, for the sake of your sanity, I would advise using only lowercase letters for MySQL object names, and limiting your use of punctuation. Because database objects tend to be even more hidden from end-user view than XML tags, readability isn't generally as big of a factor. blogposts and blogcomments, for two examples, are clear enough. Keep in mind also the following rules:

  • Do not include any spaces in object names
  • Do not use any slashes or dots (/, \, .)
  • Do not use any mathematical symbols (+, =, - [hyphen])

In short, stick to lowercase letters and lowercase letters only. At least for now. And again, see the table of reserved words that are important parts of the MySQL database system and syntax.

Class Exercise: Building a Simple Email Address Book System


Basic Database Table in MySQL

Example built in class (no data):

kasemail.sql
-- phpMyAdmin SQL Dump
-- version 2.11.7
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 10, 2008 at 12:16 PM
-- Server version: 5.0.51
-- PHP Version: 5.2.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `test`
--

-- --------------------------------------------------------

--
-- Table structure for table `kasemail`
--

CREATE TABLE IF NOT EXISTS `kasemail` (
  `kasid` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
  `kasemail` TEXT NOT NULL,
  `kasfirstn` TINYTEXT NOT NULL,
  `kaslastn` TINYTEXT NOT NULL,
  `kascontype` VARCHAR(12) NOT NULL,
  `kasnotes` TEXT NOT NULL,
  PRIMARY KEY  (`kasid`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=201 ;


Building Basic Forms in XHTML

Example built in class:

form.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add a Contact</title>
</head>

<body>
<form id="contactform" action="script.php" method="post" enctype="multipart/form-data">
    <fieldset>
        <label for="kasemail">Email:</label>
    <input type="text" id="kasemail" name="kasemail" value="" />
        <label for="kasfirstn">First Name:</label>
        <input type="text" id="kasfirstn" name="kasfirstn" value="" />
        <label for="kaslastn">First Name:</label>
    <input type="text" id="kaslastn" name="kaslastn" value="" />
    </fieldset>
    <fieldset>
    <label for="contacttype">Is this your Mobile, Home, or Work number?</label>
    <select id="contacttype" name="contacttype">
        <option value="Friend" selected="selected">Friend</option>
        <option value="Family">Family</option>
        <option value="Coworker">Coworker</option>
    </select>
    </fieldset>
    <fieldset>
    <textarea id="comments" name="comments" cols="40" rows="8"></textarea>
    </fieldset>
    <fieldset>
    <input type="submit" id="submit" name="submit" value="Submit Contact" />
    </fieldset>
</form>
</body>
</html>

PHP's handling of $_POST

Example script from class (put in same folder as form.htm on XAMPP to test):

script.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<pre>
<?php
print_r($_POST);
?>
</pre>
</body>
</html>

There are no comments on this page. [Add comment]

XHTML 1.0 :: CSS :: Powered by WikkaWiki