<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pam Van Londen &#187; Database</title>
	<atom:link href="http://pamvanlonden.com/category/knowledge/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://pamvanlonden.com</link>
	<description>Corvallis Artist, Oregon Artist. Creating Every Day...paintings, web sites, and courses Oregon daily painter, murals and portraits. Corvallis Web Designer / Web Developer. Original abstract landscape oil paintings</description>
	<lastBuildDate>Sat, 04 Feb 2012 02:56:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MySQL Import / Export Tips (Mac)</title>
		<link>http://pamvanlonden.com/mysql-import-export-tips-mac/</link>
		<comments>http://pamvanlonden.com/mysql-import-export-tips-mac/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 22:25:27 +0000</pubDate>
		<dc:creator>jamesholladay</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://pamvanlonden.com/?p=1979</guid>
		<description><![CDATA[<a href="http://pamvanlonden.com/mysql-import-export-tips-mac/"><img align="left" hspace="5" width="150" src="http://pamvanlonden.com/wp-content/uploads/2009/03/mysqlexport.gif" class="alignleft wp-post-image tfe" alt="MySQL Export screen" title="MySQL Export screen" /></a>Here are steps to take to save / export a database, and then to import it to copy or restore a database: Export to a text file Save as a .sql file Go to PHPMyAdmin Click on the &#8216;Import&#8217; tab Browse for your .sql file If you have latin1 encoding, make sure to select that [...]]]></description>
			<content:encoded><![CDATA[<p>Here are steps to take to save / export a database, and then to import it to copy or restore a database:</p>
<ol>
<li>Export to a text file</li>
<div id="attachment_1980" class="wp-caption alignnone" style="width: 510px"><a href="http://pamvanlonden.com/wp-content/uploads/2009/03/mysqlexport.gif"><img class="size-full wp-image-1980" title="MySQL Export screen" src="http://pamvanlonden.com/wp-content/uploads/2009/03/mysqlexport.gif" alt="MySQL Export screen" width="500" height="292" /></a><p class="wp-caption-text">MySQL Export screen</p></div>
<li>Save as a .sql file</li>
<li>Go to PHPMyAdmin</li>
<li>Click on the &#8216;Import&#8217; tab</li>
<li>Browse for your .sql file</li>
<li>If you have latin1 encoding, make sure to select that in the encoding drop-down menu. For any other encoding, be sure that the file and the drop-down menu&#8217;s encoding are the same.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://pamvanlonden.com/mysql-import-export-tips-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Login Scripts</title>
		<link>http://pamvanlonden.com/login-scripts/</link>
		<comments>http://pamvanlonden.com/login-scripts/#comments</comments>
		<pubDate>Fri, 15 Sep 2006 15:21:10 +0000</pubDate>
		<dc:creator>Pam Van Londen</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://i-dev.us/login-scripts/</guid>
		<description><![CDATA[<a href="http://pamvanlonden.com/login-scripts/"><img align="left" hspace="5" width="150" height="150" src="http://pamvanlonden.com/wp-content/plugins/thumbnail-for-excerpts/tfe_no_thumb.png" class="alignleft wp-post-image tfe" alt="" title="" /></a>Readings PHP6 and MySQL5 for Dynamic Web Sites Larry Ullman. Visual QuickPro Guide. Peachpit Press. 2008. Collecting and storing user data from a web site has many purposes: Track the kinds of visitors and their needs Target content to specific vistors Restrict content to adults Secure transactions, such as forum conversations, product purchases, and download [...]]]></description>
			<content:encoded><![CDATA[<p><!--Add content here--></p>
<div class="floatingcontainer">
<h4>Readings</h4>
<dl>
<dt><a href="http://www.larryullman.com/books/php-6-and-mysql-5-for-dynamic-web-sites-visual-quickpro-guide-3rd-edition/" target="_blank">PHP6 and MySQL5 for Dynamic Web Sites</a></dt>
<dd>Larry Ullman. Visual QuickPro Guide. Peachpit Press. 2008. </dd>
</dl>
</div>
<p>Collecting and storing user data from a web site has many purposes:</p>
<ul>
<li>Track the kinds of visitors and their needs</li>
<li>Target content to specific vistors</li>
<li>Restrict content to adults</li>
<li>Secure transactions, such as forum conversations, product purchases, and download copyrighted material</li>
<li>Reduce spam in unrestricted areas of a site</li>
</ul>
<p>While user data can be stored in a file on the server, it is more secure when stored in a database. Many web hosts provide PHP and MySQL connectivity with their accounts. These accounts often provide one or more databases with multiple users who have their own login credentials for accessing the database. Management of the database is either one manually by the hosts&#8217; staff or within an Account Management tool like Plesk or CPanel. OSU Provides one database per student/staff, which can be activated by logging into onid.orst.edu, clicking Web Database, and the Create Database button. Use the database name, userid, and password in conjunction with a connection script.</p>
<p><a href="http://dmcinsights.com/phpmysql2/toc.php" target="_blank">Chapter 13</a> of <em>PHP and MySQL for Dynamic Web Sites</em> provides user registration code which you may download at no cost. Refer to the printed book for implementation.</p>
<div style="float: right; width: 350px;">
<h4>Create a Database Table for Chapter 13</h4>
<p>The Chapter 13 code requires a database table called <code>users</code>, and the following SQL query can be used along with the a connection script to create the table via a browser:</p>
<p><code>// Create the table. Only needed this one time.<br />
$blog = 'CREATE TABLE users (<br />
user_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,<br />
active BOOLEAN NULL,<br />
first_name VARCHAR(40) NOT NULL,<br />
last_name VARCHAR(40) NOT NULL,<br />
password1 VARCHAR NULL,<br />
password2 VARCHAR NULL,<br />
pass VARCHAR NOT NULL<br />
email VARCHAR(40) NOT NULL,<br />
registration_date DATETIME NOT NULL<br />
)';</code></p>
<p><code>// Run the query.<br />
if (@mysql_query ($blog)) {<br />
print '&lt;p&gt;The table has been created.&lt;/p&gt;';<br />
} else {<br />
die ('&lt;p&gt;Could not create the table because: &lt;b&gt;' . mysql_error() . '&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;The query being run was: ' . $query . '&lt;/p&gt;');<br />
}</code></p>
</div>
<p>This set of scripts, like many authentication systems provides the following components.</p>
<ul>
<li>Standard file structure</li>
<li>Include files to build the page layout</li>
<li>Error handling in a config.inc file</li>
<li>Data validation</li>
<li>Database connectivity with mysql_connect</li>
<li>Registration</li>
<li>Authentication</li>
<li>Login</li>
<li>Logout</li>
<li>Change password</li>
<li>Forgot password</li>
</ul>
<p>Another component that is useful for user authentication management is an administrative view of each user&#8217;s data. Such a tool would provide the ability to insert, edit, delete, and encript passwords, as well as backup the data. phpMyAdmin is a tool provided with OSU&#8217;s ONID accounts that allows staff, students, and faculty to manage the their databases, including user authentication tables.</p>
]]></content:encoded>
			<wfw:commentRss>http://pamvanlonden.com/login-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Displaying database content with MySQL queries</title>
		<link>http://pamvanlonden.com/displaying-database-content-with-mysql-queries/</link>
		<comments>http://pamvanlonden.com/displaying-database-content-with-mysql-queries/#comments</comments>
		<pubDate>Fri, 15 Sep 2006 15:19:55 +0000</pubDate>
		<dc:creator>Pam Van Londen</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://i-dev.us/displaying-database-content-with-mysql-queries/</guid>
		<description><![CDATA[<a href="http://pamvanlonden.com/displaying-database-content-with-mysql-queries/"><img align="left" hspace="5" width="150" height="150" src="http://pamvanlonden.com/wp-content/plugins/thumbnail-for-excerpts/tfe_no_thumb.png" class="alignleft wp-post-image tfe" alt="" title="" /></a>Examples Download the code you see in the column at the right, prepared by Pam Van Londen and James Holladay, OSU. Readings PHP and MySQL for Dynamic Web Sites Larry Ullman. Visual QuickPro Guide. Peachpit Press. 2003. Read and try chapters 4 to 10. PHP.net Type in any php function name after the domain name [...]]]></description>
			<content:encoded><![CDATA[<p><!--Add content here--></p>
<div class="floatingcontainer">
<h4>Examples</h4>
<p><a href="http://oregonstate.edu/instruct/cs295/old/odp/artists/famous2.txt">Download the code</a> you see in the column at the right, prepared by Pam Van Londen and James Holladay, OSU.</p>
<h4>Readings</h4>
<dl>
<dt><a href="http://www.dmcinsights.com/phpmysql/scripts.php" target="_blank">PHP and MySQL for Dynamic Web Sites</a></dt>
<dd>Larry Ullman. Visual QuickPro Guide. Peachpit Press. 2003. <strong>Read and try chapters 4 to 10. </strong></dd>
<dt><a href="http://www.php.net" target="_blank">PHP.net</a></dt>
<dd>Type in any php function name after the domain name to read what it means and how to use it. <strong> </strong></dd>
</dl>
</div>
<p>A standard set of actions between PHP and MySQL is often structured like this in a PHP file:</p>
<h4><a href="javascript:one.slideit()">1. Start the script.</h4>
<p></a></p>
<div id="one" class="hiddenbox">
<pre style="overflow: auto;">&lt;?php
/* This form allows the user to add a descriptive link to a database after preview and validation
and display it on the same page.
Written by Pam Van Londen and James Holladay in 2009.
*/

// 1. Set variables for the script.
$pagetitle = "Daily Painters ";
$subtitle = "Famous Artists";
//Set the default background color for each input field.
$firstnamecolor = '#fff';
$lastnamecolor = '#fff';
$websitenamecolor = '#fff';
$imagenamecolor = '#fff';
$bionamecolor = '#fff';
//Define global variables so their values can be accessed by other PHP tags.
global $valid;
global $submitted;
global $validFirstName;
global $validLastName;
global $validWebsite;
global $validImage;
global $validBio;

//initialize variable values
if(!isset($_POST['submit'])){//if the submit button was not yet pressed
$submitted = 0;
$valid = 0;//to stop the preview from showing when the page first loads with no content.
}
if(isset($_GET['submitted'])){//lets the preview division show that the entry has been added to the database
$submitted = 1;
}</pre>
</div>
<p><script type="text/javascript">//Syntax: var uniquevar=new animatedcollapse("DIV_id", animatetime_milisec, enablepersist(true/fase), [initialstate] )
var one=new animatedcollapse("one", 500, true)
</script></p>
<h4><a href="javascript:two.slideit()">2. Include site-wide files.</a></h4>
<div id="two" class="hiddenbox">
<pre>// 2. Display the template header.
include '../header.htm' ;</pre>
<h5>Open a connection to the database.</h5>
<pre>// Connect to the database.
require_once ('../../connect.php');</pre>
</div>
<p><script type="text/javascript">//Syntax: var uniquevar=new animatedcollapse("DIV_id", animatetime_milisec, enablepersist(true/fase), [initialstate] )
var two=new animatedcollapse("two", 500, true)
</script></p>
<h4><a href="javascript:three.slideit()">3. Verify the form data.</a></h4>
<div id="three" class="hiddenbox">
<pre style="overflow: auto;">// 3. Set up the preview validation.
//if the preview button is clicked, set $valid to 1, we will make it 0 if any part of validation fails. Set all other validation-related variables to 1 or true.
if(isset($_POST['preview'])){//if the preview button is clicked
  $valid = 1;
  $validFirstName = true;
  $validLastName = true;
  $validWebsite = true;
  $validImage = true;
  $validBio = true;
}

//Validate each field.
if(isset($_POST['first_name'])){
  if(!ctype_alpha($_POST['first_name']) || empty($_POST['first_name'])){//must not be empty, must be alphabetic.
    //if not valid, change background color of input element, set pertinant validation variables to 0 or false.
    $valid = 0;
	$firstnamecolor = '#FFCC99';
	$validFirstName = false;
  }
}
if(isset($_POST['last_name'])){
  if(!ctype_alpha($_POST['last_name']) || empty($_POST['last_name'])){//must not be empty, must be alphabetic.
	//if not valid, change background color of input element, set pertinant validation variables to 0 or false.
    $valid = 0;
	$lastnamecolor = '#FFCC99';
	$validLastName = false;
  }
}
if(isset($_POST['website'])){
  $webURL = $_POST['website'];
  if(@fopen($webURL,'r') === false || empty($_POST['website'])){//must not be empty, URL must exist.
	//if not valid, change background color of input element, set pertinant validation variables to 0 or false.
    $valid = 0;
	$websitecolor = '#FFCC99';
	$validWebsite = false;
  }
}
if(isset($_POST['image'])){
  $imgURL = $_POST['image'];
  if(@GetImageSize("$imgURL") === false || empty($_POST['image'])){//must not be empty, an image must exist at the specified URL.
    //if not valid, change background color of input element, set pertinant validation variables to 0 or false.
    $valid = 0;
	$imagecolor = '#FFCC99';
	$validImage = false;
  }
}
if(isset($_POST['bio'])){
  if(empty($_POST['bio'])){//must not be empty.
    //if not valid, change background color of input element, set pertinant validation variables to 0 or false.
    $valid = 0;
	$biocolor = '#FFCC99';
	$validBio = false;
  }
}</pre>
<h5>3.1 Handle the data given by the visitor.</h5>
<pre style="overflow: auto;">global $submitted;
// Handle the form when submit is clicked.
if(isset($_POST['submit'])){
  if(!$submitted){//change the $submitted variable to 1, after clicking the submit button
   $submitted = 1;

    // Insert new data from the form into the database

    // 3.1 Grab field data from the form and protect against SQL injections (stop any code inserted into the form field from running, which could erase our database tables).
	$cleanFirstName = mysql_real_escape_string($_POST['first_name']);
	$cleanLastName = mysql_real_escape_string($_POST['last_name']);
	$cleanWebsite = mysql_real_escape_string($_POST['website']);
	$cleanImage = mysql_real_escape_string($_POST['bio']);
	$cleanBio = mysql_real_escape_string($_POST['image']);</pre>
<h5>3.2 Construct SQL INSERT query.</h5>
<pre style="overflow: auto;">// 3.2 Construct the query.
    $insert = "INSERT INTO artists (user_id, first_name, last_name, website, bio, image, registration_date) VALUES (
	   'NULL',
	   '{$cleanFirstName}',
	   '{$cleanLastName}',
	   '{$cleanWebsite}',
	   '{$cleanImage}',
       '{$cleanBio}',
	   NOW()
	)";</pre>
<h5>3.3 Execute SQL query, saving visitor data to the database.</h5>
<pre style="overflow: auto;">// 3.3 Send the data to the database
	if(@mysql_query($insert)){
	  print '&lt;p class="alert"&gt;Entry added.&lt;/p&gt;';
	}
	else{
	  die("&lt;p&gt;Could not add the entry because: it was probably a duplicate, or &lt;b&gt;" . mysql_error() . "&lt;/b&gt;. The query was $query.&lt;/p&gt;");
	}

	//this works to keep data from resubmitting on refresh, but no 'submitted' message will appear, and it requires javascript to be turned on.
	echo "&lt;script&gt;window.location.replace('redirect.php?name=".$_POST['first_name']."');&lt;/script&gt;";

  }//end if for insert
}</pre>
</div>
<p><script type="text/javascript">//Syntax: var uniquevar=new animatedcollapse("DIV_id", animatetime_milisec, enablepersist(true/fase), [initialstate] )
var three=new animatedcollapse("three", 500, true)
</script></p>
<h4><a href="javascript:four.slideit()">4. Add content from the database.</a></h4>
<div id="four" class="hiddenbox">
<h5>4.1 Query the database.</h5>
<pre style="overflow: auto;">// 4. Display selected files from the table and order them.

// 4.1 Display the list of artists in ascending order by last name.
$show = 'SELECT * FROM artists ORDER BY last_name ASC';</pre>
<h5>4.2 Check for errors.</h5>
<pre style="overflow: auto;">// 4.2 Run the query; if the table has rows fo data...
if($r = mysql_query($show)){</pre>
<h5>4.3 Begin the &lt;table&gt; element.</h5>
<pre style="overflow: auto;">// 4.3 Start a division, list, and/or table before the rows are displayed.
  echo '&lt;div class="rightbox"&gt;&lt;dl&gt; ';</pre>
<h5>4.4 Loop through all records, adding a &lt;tr&gt; for each</h5>
<pre style="overflow: auto;">// 4.4 Retrieve and print every record or row along with the list or table tags each needs.
  while($row = mysql_fetch_array($r)){
	print "&lt;dt&gt;&lt;a href='{$row['website']}' &gt;{$row['last_name']}, {$row['first_name']}  

			&lt;dd&gt;&lt;img src='{$row['image']}' alt='{$row['bio']}' height='30' width='175' /&gt;

			\n";
  }</pre>
<h5>4.5 Close the &lt;table&gt; element</h5>
<pre style="overflow: auto;">// 4.5 End the list, table, and/or division.
  echo '&lt;/dl&gt;&lt;/div&gt;';
}</pre>
</div>
<p><script type="text/javascript">//Syntax: var uniquevar=new animatedcollapse("DIV_id", animatetime_milisec, enablepersist(true/fase), [initialstate] )
var four=new animatedcollapse("four", 500, true)
</script></p>
<h4><a href="javascript:five.slideit()">5. If an error occured while inserting the form data into the database, add an error message.</a></h4>
<div id="five" class="hiddenbox">
<pre style="overflow: auto;">// 5. Error - Query didn't run.
else{
  die ('&lt;p&gt;Could not retrieve the data because: &lt;b&gt;' . mysql_error() . "&lt;/b&gt;. The query was $show.&lt;/p&gt;");
}// End of query IF.</pre>
</div>
<p><script type="text/javascript">//Syntax: var uniquevar=new animatedcollapse("DIV_id", animatetime_milisec, enablepersist(true/fase), [initialstate] )
var five=new animatedcollapse("five", 500, true)
</script></p>
<h4><a href="javascript:six.slideit()">6. Close the database connection.</a></h4>
<div id="six" class="hiddenbox">
<pre>// 6. Close the database connection.
mysql_close($dbc); 

// Close the php script.
?&gt;</pre>
</div>
<p><script type="text/javascript">//Syntax: var uniquevar=new animatedcollapse("DIV_id", animatetime_milisec, enablepersist(true/fase), [initialstate] )
var six=new animatedcollapse("six", 500, true)
</script></p>
<h4><a href="javascript:seven.slideit()">7. Add the form.</a></h4>
<div id="seven" class="hiddenbox">
<pre style="overflow: auto;">&lt;!-- 7. display a form with validadtion, preview, and submit to database options. --&gt;
&lt;form name="addfamous"  id="addfamous" action="&lt;?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?&gt;"  method="post"&gt; 

&lt;!--7.1 preview is hidden until preview button is clicked --&gt;
  &lt;div id="previewFormData"&gt;
  &lt;?php
    global $valid;
	global $submitted;
	if($submitted){//clear the form if it was submitted.
	  echo '&lt;fieldset class="preview"&gt;&lt;legend style="margin-top:30px;"&gt;Preview&lt;/legend&gt;&lt;dl&gt;';
	  print "&lt;dt&gt;&lt;p&gt;Your Information has been submitted, ".$_GET['submitted'].".&lt;/p&gt;&lt;/dt&gt;";
	  echo '&lt;/dl&gt;&lt;/fieldset&gt;';
	  $valid = 0;
	}
	else if($valid == 1){//if the form is valid, but not yet submitted, write the content to the preview division.
	  echo '&lt;fieldset class="preview"&gt;&lt;legend style="margin-top:30px;"&gt;Preview&lt;/legend&gt;&lt;dl&gt;';
	  print "&lt;dt&gt;&lt;a href='{$_POST['website']}' style='color:#000;' &gt;{$_POST['last_name']}, {$_POST['first_name']}&lt;/a&gt;&lt;/dt&gt;
			 &lt;dd&gt;&lt;img src='{$_POST['image']}' alt='{$_POST['bio']}' height='30' width='175' /&gt;&lt;/dd&gt;
			 \n";
	  echo '&lt;/dl&gt;
	        &lt;label for="submit"&gt;&lt;input name="submit" id="submit" class="confirm" type="submit"  value="Add to List" tabindex="y" accesskey="a"  /&gt;&lt;/label&gt;
			&lt;/fieldset&gt;';
	}
  ?&gt;
  &lt;/div&gt;

&lt;!--7.2 form instructions--&gt;
  &lt;p&gt;Please use this form to add a famous artist, a link to their web site, and an image of their work. &lt;/p&gt;
  &lt;p&gt;&lt;span class="example"&gt;Required fields are marked with an orange  &lt;span class="alert"&gt;*&lt;/span&gt;
  and accesskeys are labeled with an &lt;u&gt;underline&lt;/u&gt; and can be used with the Alt-Shift (Windows) or Control (Mac) keys.&lt;/span&gt; &lt;/p&gt;
&lt;!-- 7.3 form fields--&gt;
  &lt;fieldset&gt;
    &lt;legend&gt;Who do you consider famous?&lt;/legend&gt;
    &lt;p&gt;&lt;label for="first_name"&gt;&lt;u&gt;F&lt;/u&gt;irst name  &lt;span class="alert"&gt; *&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
      &lt;input  style="background-color:&lt;?php echo $firstnamecolor?&gt;" name="first_name" id="first_name" type="text" tabindex="1" accesskey="f" value="&lt;?php echo $_POST['first_name']; ?&gt;"  size="20" maxlength="30"   /&gt;&lt;?php global $validFirstName; if (isset ($_POST['preview'])) { if(!$validFirstName){echo '&lt;p class="invalidData" style="color:#f00;"&gt;Please enter a'; if(!empty($_POST['first_name'])){echo ' valid';}echo ' first name.&lt;/p&gt;';}} ?&gt; &lt;/p&gt;

    &lt;p&gt;&lt;label for="last_name"&gt;Last &lt;u&gt;n&lt;/u&gt;ame  &lt;span class="alert"&gt; *&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
      &lt;input  style="background-color:&lt;?php echo $lastnamecolor?&gt;" name="last_name" id="last_name" type="text" tabindex="2" accesskey="n" value="&lt;?php echo $_POST['last_name']; ?&gt;"  size="20" maxlength="30"   /&gt;&lt;?php global $validLastName; if (isset ($_POST['preview'])) { if(!$validLastName){echo '&lt;p class="invalidData" style="color:#f00;"&gt;Please enter a'; if(!empty($_POST['last_name'])){echo ' valid';}echo ' last name.&lt;/p&gt;';}} ?&gt; &lt;/p&gt;

    &lt;p&gt;&lt;label for="website"&gt;&lt;u&gt;W&lt;/u&gt;ebsite address &lt;span class="alert"&gt; *&lt;/span&gt; &lt;/label&gt;&lt;br /&gt;
      &lt;input style="background-color:&lt;?php echo $websitecolor?&gt;"  name="website" id="website" type="text" tabindex="3" accesskey="w" value="&lt;?php echo $_POST['website']; ?&gt;" size="20" maxlength="100"  /&gt;&lt;?php global $validWebsite; if (isset ($_POST['preview'])) { if(!$validWebsite){echo '&lt;p class="invalidData" style="color:#f00;"&gt;Please enter a'; if(!empty($_POST['website'])){echo ' valid';}echo ' website address.&lt;/p&gt;';}} ?&gt; &lt;br /&gt;
      &lt;span class="example"&gt;Example: http://www.site.com&lt;/span&gt;&lt;/p&gt;

    &lt;p&gt;&lt;label for="image"&gt;&lt;u&gt;I&lt;/u&gt;mage of their work or portrait &lt;span class="alert"&gt; *&lt;/span&gt; &lt;/label&gt;&lt;br /&gt;
      &lt;input  style="background-color:&lt;?php echo $imagecolor?&gt;" name="image" id="image" type="text" tabindex="4" accesskey="i" value="&lt;?php echo $_POST['image']; ?&gt;" size="20" maxlength="100"  /&gt;&lt;?php global $validImage; if (isset ($_POST['preview'])) { if(!$validImage){echo '&lt;p class="invalidData" style="color:#f00;"&gt;Please enter a'; if(!empty($_POST['image'])){echo ' valid';}else{echo 'n';}echo ' image URL.&lt;/p&gt;';}} ?&gt; &lt;br /&gt;
      &lt;span class="example"&gt;Example: http://www.site.com/picture.jpg&lt;/span&gt;&lt;/p&gt;

    &lt;p&gt;&lt;label for="bio"&gt;&lt;u&gt;B&lt;/u&gt;iography (short) &lt;span class="alert"&gt; *&lt;/span&gt; &lt;/label&gt;&lt;br /&gt;
      &lt;textarea style="background-color:&lt;?php echo $biocolor?&gt;" name="bio" id="bio" tabindex="5" accesskey="b" cols="20" rows="6" &gt;&lt;?php echo $_POST['bio']; ?&gt;&lt;/textarea&gt;&lt;?php global $validBio; if (isset ($_POST['preview'])) { if(!$validBio){echo '&lt;p class="invalidData" style="color:#f00;"&gt;Please enter a'; if(!empty($_POST['bio'])){echo ' valid';}echo ' bio.&lt;/p&gt;';}} ?&gt; &lt;br /&gt;
      &lt;span class="example"&gt;No html allowed; just plain text.&lt;/span&gt;
&lt;!-- note that textarea size attributes are rows and columns, not size --&gt;
    &lt;/p&gt;
  &lt;/fieldset&gt;
&lt;!--7.4 submit if preview is ok and all fields are valid --&gt;
  &lt;fieldset&gt;
    &lt;legend&gt;Preview will show at the top of the page.&lt;/legend&gt;
    &lt;label for="submit"&gt;&lt;input name="preview" id="preview" class="validator"  type="submit"   value="Preview" tabindex="6" accesskey="v"  /&gt;
    to &lt;u&gt;v&lt;/u&gt;iew your submission.&lt;/label&gt;
  &lt;/fieldset&gt;
&lt;/form&gt;</pre>
</div>
<p><script type="text/javascript">//Syntax: var uniquevar=new animatedcollapse("DIV_id", animatetime_milisec, enablepersist(true/fase), [initialstate] )
var seven=new animatedcollapse("seven", 500, true)
</script></p>
<h4><a href="javascript:eight.slideit()">8. Include the site template.</a></h4>
<div id="eight" class="hiddenbox">
<pre style="overflow: auto;">&lt;!--8. end the template items --&gt;
&lt;?php
include ('../footer.htm');
?&gt;</pre>
</div>
<p><script type="text/javascript">//Syntax: var uniquevar=new animatedcollapse("DIV_id", animatetime_milisec, enablepersist(true/fase), [initialstate] )
var eight=new animatedcollapse("eight", 500, true)
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://pamvanlonden.com/displaying-database-content-with-mysql-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Database Design</title>
		<link>http://pamvanlonden.com/database-design/</link>
		<comments>http://pamvanlonden.com/database-design/#comments</comments>
		<pubDate>Fri, 15 Sep 2006 15:19:35 +0000</pubDate>
		<dc:creator>Pam Van Londen</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://i-dev.us/database-design/</guid>
		<description><![CDATA[<a href="http://pamvanlonden.com/database-design/"><img align="left" hspace="5" width="150" height="150" src="http://pamvanlonden.com/wp-content/plugins/thumbnail-for-excerpts/tfe_no_thumb.png" class="alignleft wp-post-image tfe" alt="" title="" /></a>Readings SQLCourse.com Free interactive course online, for learning MySQL. MySQL tutorial MySQL Reference manual, chapter 3. Database Enabled Websites Tutorial recommended by OSU PHP documentation. A database is a collection of related data. It can also be viewed as a collection of related tables. Tables have sets of fields. Field types define the kind of [...]]]></description>
			<content:encoded><![CDATA[<div class="floatingcontainer">
<h4>Readings</h4>
<dl>
<dt><a href="http://www.sqlcourse.com/" target="_blank">SQLCourse.com</a></dt>
<dd>Free interactive course online, for learning MySQL.</dd>
<dt> <a href="http://www.peachpit.com/content/images/0321159462/companionsite/links.html" target="_blank">MySQL tutorial </a></dt>
<dd>MySQL Reference manual, chapter 3. </dd>
<dt><a href="http://www.awtrey.com/support/dbeweb/" target="_blank">Database Enabled Websites</a></dt>
<dd>Tutorial recommended by OSU PHP documentation. </dd>
</dl>
</div>
<p>A <span style="font-weight: bold;">database</span> is a collection of related data. It can also be viewed as a collection of related tables.</p>
<p><span style="font-weight: bold;">Tables</span> have sets of fields. <a title="MySQL Field Types" href="http://dev.mysql.com/doc/refman/5.0/en/data-types.html">Field types</a> define the kind of data the field can contain, including:</p>
<dl>
<dt>String</dt>
<dd>Stores text and numerical characters.</dd>
<dt> Numeric</dt>
<dd>Stores numbers that can be calculated. </dd>
<dt> Date and time</dt>
<dd>Stores dates and times. </dd>
<dt> Boolean, or logical </dt>
<dd>Accepts one of only two specified values. </dd>
</dl>
<p>It is possible to create tables; define fields; and enter, query, and display data using scripts in web pages. For this course, we will use three &#8220;tools&#8221; to do this:</p>
<dl>
<dt>MySQL</dt>
<dd>An open-source database residing on the ONID server; each student gets one.</dd>
<dt>phpMyAdmin</dt>
<dd> The interface provided to create tables, define fields, enter, browse, test, and query data.</dd>
<dt>PHP scripts</dt>
<dd>In web pages, to enter, query, and display data from database tables.</dd>
</dl>
<h3>MySQL database via your web server account</h3>
<p>MySQL is an open-source database. Most web server accounts include the use of at least one MySQL database. To design a database, think about data you would like collected from your visitors. What do you want to know about them?</p>
<p>Start with pen and paper to list the ideas about like sets of data you want to collect. <strong>Organize the sets into:</strong></p>
<ul>
<li>Tables (or entities)</li>
<li>Fields</li>
<li>Relationships (how one table uses data from another table)</li>
</ul>
<p>For instance, if you just want to track inquiries, a single table might meet your needs. This database uses one table (contact) and that table uses 9 fields:</p>
<table border="0">
<caption> Inquiry database structure<br />
</caption>
<tbody>
<tr align="left" valign="top">
<th scope="col">Table Name</th>
<th scope="col">Fields needed</th>
</tr>
<tr align="left" valign="top">
<td><span class="chart">Contact</span></td>
<td>
<p class="chart">CustomerNumber<br />
FirstName<br />
LastName<br />
Address<br />
City<br />
State<br />
Zip<br />
Phone<br />
Email</p>
</td>
</tr>
</tbody>
</table>
<p>If you have more complicated data to collect, group related fields in separate tables. For instance, if you want to track statistics of your favorite sports teams you may end up with 4 tables, several fields per table, and relationships between fields/tables:</p>
<table border="0">
<caption> Team standings database structure<br />
</caption>
<tbody>
<tr align="left" valign="top">
<th width="89" scope="col">Table Name</th>
<th width="96" scope="col">Fields</th>
<th width="65" scope="col">Type</th>
</tr>
<tr align="left" valign="top">
<td class="chart" scope="row">Teams</td>
<td>
<p class="chart">Index<br />
Rank<br />
Name<br />
Location<br />
Sport</p>
</td>
<td>
<p class="chart">Int<br />
Int<br />
Varchar<br />
Varchar<br />
Varchar<br />
Varchar</p>
</td>
</tr>
<tr align="left" valign="top">
<td class="chart" scope="row">Players &amp; Coaches</td>
<td>
<p class="chart">Index<br />
TeamIndex<br />
Rank<br />
Name<br />
Location<br />
Age<br />
Position<br />
Sport<br />
Comments</p>
</td>
<td>
<p class="chart">Int<br />
Int<br />
Int<br />
Varchar<br />
Int<br />
Varchar<br />
Varchar<br />
Varchar<br />
Text</p>
</td>
</tr>
<tr align="left" valign="top">
<td class="chart" scope="row">Sport</td>
<td class="chart">
<p class="chart">SportType<br />
SeasonStart<br />
SeasonEnd</p>
</td>
<td class="chart">Varchar<br />
Date<br />
Date</td>
</tr>
<tr align="left" valign="top">
<td class="chart" scope="row">Matches</td>
<td class="chart">
<p class="chart">Index<br />
Location<br />
DateStart<br />
DateEnd<br />
Rank</p>
</td>
<td class="chart">Int<br />
Varchar<br />
Date<br />
Date<br />
Int</td>
</tr>
</tbody>
</table>
<p>Once you decide the number of tables you need, and what you want to call each field,<strong> define the field types</strong>.  Basic types include:</p>
<dl>
<dt>Integer (int)</dt>
<dd>Numerals that will be calculated.</dd>
<dt>Float</dt>
<dd>A number with decimals.</dd>
<dt>Variable Character (varchar)</dt>
<dd>Numerals and text in short strings; usually 100 characters or less. </dd>
<dt>Text (text)</dt>
<dd>Numerals and text for long passages. </dd>
<dt>Date (date)</dt>
<dd>Years months, and days. The default is year-month-day. </dd>
</dl>
<p><strong>Some attributes to note include:</strong></p>
<dl>
<dt>Index</dt>
<dd>Provides a unique identifier for the row/record in the table. Can be the primary key field. Use &#8220;idx&#8221; rather than &#8220;index&#8221; for the field name; it is sometimes dangerous to use a field name that is already a standard database term/variable/type, etc. </dd>
<dt>Null</dt>
<dd>Means the field can remain empty; the visitor doesn&#8217;t have to fill this field in.</dd>
<dt>Not Null</dt>
<dd>Means the field cannot remain empty; the visitor must fill in the field. </dd>
</dl>
<p>When you know what fields you need, you can either <strong>define the tables and fields using:</strong></p>
<ul>
<li><a title="phpMyAdmin Site" href="http://phpmyadmin.sf.net/">phpMyAdmin</a>
<ul>
<li>Link to it from your database set up page accessible when you login to your web server account.</li>
<li>Requires your database login and password.</li>
</ul>
</li>
<li>PHP Scripts
<ul>
<li>Find or write a script that creates a tables and fields.</li>
</ul>
</li>
</ul>
<p>Once your fields are defined, <strong>build a web page form to collect the data.</strong> Use the same field names in your form as used in your database.</p>
<p><strong>You&#8217;ll need snippets of code to:</strong></p>
<ul>
<li>Login/connect to the database</li>
<li>Add a row to the database</li>
<li>Add data to the row</li>
<li>Display the new row and/or a set of records/rows</li>
<li>Close the connection to the database</li>
</ul>
<p>Larry Ullman, author of the Visual Quickstart Guides for PHP and MySQL, says &#8220;One of the best ways to determine what information should be stored in a database is to clarify what questions will be asked of it and what data would be included in the answers.&#8221;</p>
<p>See <a title="Displaying database content with MySQL queries" rel="bookmark" href="http://pamvanlonden.com/displaying-database-content-with-mysql-queries/">Displaying database content with MySQL queries for example code.<br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pamvanlonden.com/database-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

