spacer



Home News Links People Catalog
spacer
activepages

We spent some class time in Week 11 looking at a case study in simple back-end data integration connected to an HTML form. The case study starts with a restaurant site generated by a student of mine in 2001:

http://www.greenmango.ca/

The student manages providing a static menu from the website at:
http://www.greenmango.ca/menu.html

The form we created can be seen at:
http://communitylearningpartnership.org/menu_form.html

You can see the menu dynamically at http://communitylearningpartnership.org/green_menu.php

The PHP page that integrates form data into the back-end database is below (note that all relative URL's are relative to http://communitylearningpartnership.org/):

The dynamic menu created from the back-end database is here (the code for which is below, minus the password which I have replaced with 'password' for learning purposes:
http://communitylearningpartnership.org/green_mango.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>Green Mango - The best of Thai cuisine in Toronto</title>
<script type="text/javascript" src="mootools.js"></script>
<script type="text/javascript" src="moodalbox.js"></script>
<link rel="stylesheet" href="moodalbox.css" type="text/css" media="screen" />
<script language="JavaScript" type="text/javascript" src="popup.js"></script>
</head>
<body style="background:#1f150c">
<div id="result_table" style="position:absolute;top:12px;left:400px">
<h1 style="color:#88CC00">LUNCH MENU</h1>
<table border="0" cellpadding="4" cellspacing="0" style="font-family:Verdana;font-size:14px;color:#FFFFFF;width:600">
<tr>
<th>Item Name</th><th>Ingredients</th><th>Price</th><th>Preparation</th><th>Comments</th>
</tr>
<tr>
<?php
//Connect To Database
$hostname='localhost';
$username='clpweb_clpuser';
$password='password';
$dbname='clpweb_clp';
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');

//select - use this database
mysql_select_db($dbname);
if (isset($_POST['price'])) {
    $query = "INSERT INTO Menu_Item VALUES ('".$_POST['name']."','".$_POST['recipe']."',".$_POST['price'].",".$_POST['prep'].",'".$_POST['comments']."')";
    $result = mysql_query($query);
}
$query = "SELECT distinct * from Menu_Item ORDER BY name ASC";

//echo 'Running Query: '.$query;

$result = mysql_query($query);
if($result) {
  while($row = mysql_fetch_array($result)){
    echo '<tr><td>';
    echo $row['name'];
    echo '</td>';
    echo '<td>';
    echo $row['recipe'];
    echo '</td>';
    echo '<td>';
    echo $row['price'];
    echo '</td>';
    echo '<td>';
    echo $row['prep'];
    echo ' minutes</td>';
    echo '<td>';
    echo $row['comments'];
    echo '</td></tr>';
  }
}
?>
</tr>
</table>
<span style="font-size:12px;color:#ffffff;align:center">
&nbsp;<br/>
</span>
<div id="bottom">
<img src="images/Green-Mango_11.png" border="0" />
</div>
</div>
<div id="nav" style="position:absolute;top:20px;left:100px">
<img src="images/nav.png" border="0" />
</div>
<div id="left" style="position:absolute;top:220px;left:6px">
<img src="images/menus.png" border="0" />
</div>
</map>
</body>
</html>