<?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>John Keston Classes &#187; IM3420 Advanced Scripting Languages</title>
	<atom:link href="http://aim.johnkeston.com/category/im3420/feed/" rel="self" type="application/rss+xml" />
	<link>http://aim.johnkeston.com</link>
	<description>Curriculum for classes taught by John Keston at Art Institutes Minnesota</description>
	<lastBuildDate>Wed, 01 Feb 2012 18:46:18 +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>Syllabus and Meeting Times</title>
		<link>http://aim.johnkeston.com/im3420/syllabus-and-meeting-times-3/</link>
		<comments>http://aim.johnkeston.com/im3420/syllabus-and-meeting-times-3/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 06:00:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/03/syllabus-and-meeting-times-3/</guid>
		<description><![CDATA[IM3420 Advanced Scripting Languages Students will refine dynamic scripting skills to develop complex interactivity and applications (applets). The course also examines client-side forms in conjunction with server-side scripting applications. Note: WDIM students must earn a C or better to pass this capstone course Instructor: John Keston (Schedule) Meeting Times and Location (T/R): Session 1 / [...]]]></description>
			<content:encoded><![CDATA[<h1>IM3420 Advanced Scripting Languages</h1>
<p>Students will refine dynamic scripting skills to develop complex interactivity and applications (applets). The course also examines client-side forms in conjunction with server-side scripting applications. <strong>Note:</strong> WDIM students must earn a C or better to pass this capstone course</p>
<h3>Instructor: <a href="mailto:jkeston@aii.edu">John Keston</a> <a href="http://aim.johnkeston.com/">(Schedule)</a></h3>
<p><strong>Meeting Times and Location (T/R):</strong><br />
Session 1 / Session 2<br />
Room P108 (The Pence Building on 8th and Hennepin) 11:00am &#8211; 2:00pm</p>
<p><strong>Syllabus</strong>:<br />
<a href='http://aim.johnkeston.com/wp-content/uploads/2011/04/im3420_adv_scripting_sp2011_keston.doc'>IM3420 Advanced Scripting Languages</a></p>
<p><strong>Assignments / Projects:</strong></p>
<table bgcolor="#ffffff" border="0" cellpadding="2" cellspacing="2" width="100%">
<tr bgcolor="#a4ced7">
<td width="64%"><strong>Projects</strong></td>
<td width="36%"><strong>Due</strong></td>
</tr>
<tr valign="top">
<td bgcolor="#dddddd" width="64%">Guest Book &#8211; Stores site guests in a flat file</td>
<td bgcolor="#dddddd">Session 1, Week 4</td>
</tr>
<tr valign="top">
<td bgcolor="#dddddd">Links &#8211; Store and manage links in a flat file using associative arrays</td>
<td bgcolor="#dddddd">Session 2, Week 6</td>
</tr>
<tr valign="top">
<td bgcolor="#dddddd">News &#8211; Store and manage news articles in a database</td>
<td bgcolor="#dddddd">Session 1, Week 11</td>
</tr>
<tr valign="top">
<td bgcolor="#dddddd">Final Exam</td>
<td bgcolor="#dddddd">Session 2, Week 11</td>
</tr>
</table>
<p><strong>Notice:</strong> All the code examples included in the class content for IM3420 Advanced Scripting Languages are what I refer to as skeletons. They are incomplete, some have bugs, and although they may run properly they are not intended for use in production. During the lectures and studio/lab sessions the examples will be developed further and fine tuned. You may use them as a starting point for your projects, but will be expected to improve on the examples and add functionality.</p>
<p><a href="../week-1-3">Week 1</a> | <a href="../week-2-3">Week 2</a> | <a href="../week-3-3">Week 3</a> | <a href="../week-4-3">Week 4</a> | <a href="../week-5-3">Week 5</a> | <a href="../week-6-3">Week 6</a><br />
<a href="../week-7-3">Week 7</a> | <a href="../week-8-3">Week 8</a> | <a href="../week-9-3">Week 9</a> | <a href="../week-10-3">Week 10</a> | <a href="../week-11-3">Week 11</a></p>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/syllabus-and-meeting-times-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Week 1</title>
		<link>http://aim.johnkeston.com/im3420/week-1-3/</link>
		<comments>http://aim.johnkeston.com/im3420/week-1-3/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 06:05:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/03/week-1-3/</guid>
		<description><![CDATA[Session 1: Make sure that you can login to your OLS account. Setup a site definition in Dreamweaver or use an FTP client to complete the php tutorial at: http://www.php.net/tut.php from &#8220;Your first PHP-enabled page&#8221; to &#8220;Dealing with forms&#8221;. Recommended Text: &#8220;Beginning PHP5&#8243; Published by WROX (Available at the bookstore) Reading assignment: 1. Please read [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Session 1: </strong>Make sure that you can login to your OLS account. Setup a site definition in Dreamweaver or use an FTP client to complete the php tutorial at: <a href="http://www.php.net/tut.php">http://www.php.net/tut.php</a> from &#8220;Your first PHP-enabled page&#8221; to &#8220;Dealing with forms&#8221;.</p>
<p>Recommended Text: &#8220;Beginning PHP5&#8243; Published by WROX (Available at the bookstore)</p>
<p><strong>Reading assignment: </strong><br />
1. Please read everything under variables<br />
<a href="http://us2.php.net/manual/en/language.variables.php" target="_blank">http://us2.php.net/manual/en/language.variables.php</a></p>
<p>2. Please read the following under Operators:<br />
Arithmetic, Assignment, Comparison, Logical and String<br />
<a href="http://us2.php.net/manual/en/language.operators.php" target="_blank">http://us2.php.net/manual/en/language.operators.php</a></p>
<p><strong>Session 2:</strong> Create an online guestbook in PHP on your student website. All PHP documents must be contained in your &#8220;public_html&#8221; directory or sub-directories within it on your OLS account. The guestbook form must have at least 10 fields (First Name, Last Name, Address, etc.) and display the results to the user on a following page. Use text fields, check boxes, radio buttons, select lists and one textarea.</p>
<p><a href='http://aim.johnkeston.com/wp-content/uploads/2007/12/php_problem_set_1.zip'>Download: PHP Problem Set 1</a><br />
1. All PHP problems within a &#8220;set&#8221; are due by the beginning of class on the next day that the class meets.<br />
2. Answers must be available via links on the OLS or comparable hosting and copied to the drop off drive.<br />
3. Solutions to each problem set will be given during demonstrations on the day that they are due.<br />
4. Grades will be collected during the solution demonstrations by an <a href="http://bestfriendsforevers.com">assigned</a> classmate.</p>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/week-1-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Week 2</title>
		<link>http://aim.johnkeston.com/im3420/week-2-3/</link>
		<comments>http://aim.johnkeston.com/im3420/week-2-3/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 06:10:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/03/week-2-3/</guid>
		<description><![CDATA[Session 1: Now we will continue our discussion on some of the fundamentals of cgi (common gateway interface) scripting, commonly refered to as server side scripting. We&#8217;ll look at usefully troubleshooting techniques such as phpinfo() and using the echo statement to display variable values. In the lab make the guestbook form populate the guests.txt flat [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Session 1: </strong>Now we will continue our discussion on some of the fundamentals of cgi (common gateway interface) scripting, commonly refered to as server side scripting. We&#8217;ll look at usefully troubleshooting techniques such as <a href="http://www.php.net/phpinfo" target="_blank">phpinfo()</a> and using the <a href="http://www.php.net/manual/en/function.echo.php" target="_blank">echo</a> statement to display variable values. In the lab make the guestbook form populate the guests.txt flat file Set the permissions to world writable and implement the following code:</font></p>
<pre class="brush: php; title: ; notranslate">
&lt;?
    $gb_file = fopen( &quot;guests.txt&quot;, &quot;a+&quot; );
    if ( fwrite($gb_file, &quot;$name\t$email\n&quot;) ) {
        $body  = &quot;My message Text...\n&quot;;
        $body .= &quot;$name\n&quot;;
        $body .= &quot;$email\n&quot;;
        mail( &quot;my_email@my_domain.edu&quot;,&quot;Guest Book Entry&quot;, $body );
        echo &quot;Thanks!&lt;br&gt;\n&quot;;
    }
    else {
        echo &quot;could not write file...&lt;br&gt;\n&quot;;
    }
?&gt;
</pre>
<p>You must create a file in the same folder called &#8220;guests.txt&#8221; for this example to work. It is also necessary to set the permissions so that the file is &#8220;world writable&#8221;. The permissions can be set using an FTP client. If you&#8217;re unsure how to do this we can go over this in class on Session 1. To check your work, view guest.txt in the browser by going to http://&lt;account_name&gt;.aisites.com/guests.txt</p>
<p><strong>Session 2:</strong> Now that your guestbook form is adding each new entry to the &#8220;guests.txt&#8221; file, create a new php document called &#8220;show_guests.php&#8221;. Write code in the script to loop through the guests.txt file and display the results in HTML. Make the email field a mailto link ( &lt;a href=&#8221;mailto:test@test.com&#8221;&gt;test@test.com&lt;/a&gt; ). Here&#8217;s an example of a loop:</p>
<pre class="brush: php; title: ; notranslate">
Example #1
&lt;?
        $gb_file = file( 'guests.txt' );
        for( $x=0; $x &lt; count($gb_file); ++$x ) {
                echo ( &quot;line $x:&quot; . $gb_file[$x] . &quot;\n&quot; );
        }
?&gt;

Example #2
&lt;?
    $gb_file = file( 'guests.txt' );
    while( list($line_nums, $lines) = each($gb_file) ) {
        echo( &quot;line $line_nums:&quot; . $lines . &quot;\n&quot; );
    }
?&gt;
</pre>
<p><a href='http://aim.johnkeston.com/wp-content/uploads/2007/12/php_problem_set_2.zip'>Download: PHP Problem Set 2</a><br />
1. All PHP problems within a &#8220;set&#8221; are due by the beginning of class on the next day that the class meets.<br />
2. Answers must be available via links on the OLS or comparable hosting and copied to the drop off drive.<br />
3. Solutions to each problem set will be given during demonstrations on the day that they are due.<br />
4. Grades will be collected during the solution demonstrations by an <a href="http://bestfriendsforevers.com">assigned</a> classmate.</p>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/week-2-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Week 3</title>
		<link>http://aim.johnkeston.com/im3420/week-3-3/</link>
		<comments>http://aim.johnkeston.com/im3420/week-3-3/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 06:15:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/04/week-3-3/</guid>
		<description><![CDATA[Session 1: Some important pre-processing is required for text areas within forms, otherwise every time a user hits enter in a text field the flat file will contain the &#8220;return&#8221; and &#8220;new line&#8221; characters. This means our flat file will essentially be corrupt because the &#8220;new line&#8221; character is used to distinguished between one record [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Session 1:</strong> Some important pre-processing is required for text areas within forms, otherwise every time a user hits enter in a text field the flat file will contain the &#8220;return&#8221; and &#8220;new line&#8221; characters. This means our flat file will essentially be corrupt because the &#8220;new line&#8221; character is used to distinguished between one record and the next. The following function replaces the character that corrupts the flat file with an HTML break tag:</p>
<pre>$comments = str_replace("\r\n","",$comments);</pre>
<p>It&#8217;s easy enough to display the file line by line, but what if you want to have each field within the lines line up within an HTML table and include other formatting options, such as bolding, or a &#8220;mailto&#8221; link?</p>
<p>In order to do this you need to use the &#8220;explode&#8221; function to extract the individual fields into an array which we can then display in a dynamic web page. See the example below (show_guests.php):</p>
<pre class="brush: xml; title: ; notranslate">
&lt;html&gt;
&lt;title&gt;My Guests&lt;/title&gt;
&lt;head&gt;&lt;/head&gt;
&lt;body&gt;
&lt;table&gt;
&lt;tr&gt;&lt;th&gt;First Name&lt;/th&gt;&lt;th&gt;Last Name&lt;/th&gt;&lt;th&gt;Email&lt;/th&gt;&lt;/tr&gt;
&lt;?
    $gb_file = file( 'guests.txt' );
    foreach( $gb_file as $line ) {
        rtrim( $line );
        $field = explode( &quot;\t&quot;, $line );
        echo( &quot;&lt;tr&gt;\n&quot; );
        echo( &quot;&lt;td&gt;&quot; . $field[0] . &quot;&lt;/td&gt;\n&quot; );
        echo( &quot;&lt;td&gt;&quot; . $field[1] . &quot;&lt;/td&gt;\n&quot; );
        echo( &quot;&lt;td&gt;&lt;a href=\&quot;mailto:$field[2]\&quot;&gt;$field[2]&lt;/a&gt;&lt;/td&gt;&quot; );
        echo( &quot;&lt;/tr&gt;&quot; );
    }
?&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Complete the guestbook project by adding your own personal design touch to the elements of the project, including the form (guestbook.html), the action (guestbook.php) and the show_guests.php script. Here&#8217;s a list of requirements for the project and how you&#8217;re expected to turn in the project:</p>
<ol>
<li>The guest book form (guestbook.html) must have at least 10 fields for the user to input.</li>
<li>User input must contain arrays by using checkboxes or a select multiple list.</li>
<li>Use loops to gather information from the arrays.</li>
<li>The form action (guestbook.php) must send an email and write the fields to the &#8220;guests.txt&#8221; file.</li>
<li>The form action must strip harmful header injection attacks.</li>
<li>The guestbook.php script should provide feedback including thanking the user after they submit the form.</li>
<li>The show_guests.php script should display all the guests in a table lined up evenly.</li>
<li>Copy all your code to the drop off drive and a link to your project on OLS.</li>
<li>This project is due Session 1, Week 4.</li>
</ol>
<p><strong>Session 2:</strong> We talked about the dynamic links page project.To begin the links project create a directory called &#8220;links&#8221; inside your &#8220;php&#8221; directory. Inside the &#8220;links&#8221; fold create a form like the one below. The form should have a text field for the url, the category and the description.</p>
<form>
<table border="0" bgcolor="#aaaaaa" cellpadding="3" cellspacing="1">
<tr bgcolor="#FFFFFF">
<td>Url:</td>
<td>
<input name="url" type="text">
      </td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Category:</td>
<td>
<input name="category" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Description:</td>
<td>
<input name="description" type="text">
      </td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2">
<input name="submit" value="add link" type="submit">
      </td>
</tr>
</table>
</form>
<p>To see a working model of the links project click <a href="http://jck362.aisites.com/links2" target="_blank">here</a>.</p>
<p><a href='http://aim.johnkeston.com/wp-content/uploads/2007/12/php_problem_set_3.zip'>Download: PHP Problem Set 3</a><br />
1. All PHP problems within a “set” are due by the beginning of class on the next day that the class meets.<br />
2. Answers must be available via links on the OLS or comparable hosting and copied to the drop off drive.<br />
3. Solutions to each problem set will be given during demonstrations on the day that they are due.<br />
4. Grades will be collected during the solution demonstrations by an assigned classmate.</p>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/week-3-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Week 4</title>
		<link>http://aim.johnkeston.com/im3420/week-4-3/</link>
		<comments>http://aim.johnkeston.com/im3420/week-4-3/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 06:44:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/04/week-4-3/</guid>
		<description><![CDATA[Session 1: Don&#8217;t forget that the &#8220;guestbook&#8221; project is due today. Create the link to the working guestbook area and copy the source files with the link file (this includes the form html document, the form&#8217;s action PHP, and the PHP script to display the guests) to the drop off drive (John Keston\mm2421\&#60;student_name&#62;). Write a [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Session 1:</strong> Don&#8217;t forget that the &#8220;guestbook&#8221; project is due today. Create the link to the working guestbook area and copy the source files with the link file (this includes the form html document, the form&#8217;s action PHP, and the PHP script to display the guests) to the drop off drive (John Keston\mm2421\&lt;student_name&gt;).</p>
<p>Write a PHP script to alphabetically display a list of categories found in the links.txt file using multi-dimensional associative arrays. This may sound hard, but it&#8217;s only 15 lines of code. Using associative arrays makes it possible to organize data such that very little code is needed to handle more complicated tasks. Here&#8217;s an example to help you along:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
  // include this at the very top of index.php
  // open the links file and insert into array
  $links_file = file( 'links.txt' );

  // loop through the file, line by line
  foreach ($links_file as $line ) {
    $line = rtrim( $line );
    $field = explode( &quot;\t&quot;, $line );
    // make sure a category and link exist
    if ( $field[0] &amp;&amp; $field[1] ) {
      // set the description to the link if absent
      if ( !$field[2] ) {
        $field[2] = $field[1];
      }
      // push each link into a hash of each category - this creates
      // a multidimensional associative array called $links_hash
      $links_hash[&quot;$field[0]&quot;][]=&quot;&lt;a href=\&quot;$field[1]\&quot;&gt;$field[2]&lt;/a&gt;&quot;;
    }
  }
  // sort the hash by the key (&quot;category&quot;)
  ksort ( $links_hash );
?&gt;
&lt;?
  // place this in the body of index.php
  // Display the Categories as links to anchors
  echo( &quot;&lt;b&gt;Categories:&lt;/b&gt;&lt;br /&gt;\n&quot; );
  while ( list($key,$value) = each($links_hash) ) {
    echo( &quot;&lt;a href=\&quot;#$key\&quot;&gt;$key&lt;/a&gt;&lt;br /&gt;\n&quot; );
  }
  reset( $links_hash );
?&gt;
</pre>
<p><strong>Session 2:</strong> Here&#8217;s an example of code which will display all the links after they have been placed in the hash called $links_hash. This code must be placed in the same document AND after the code example from Session 1.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
  // add to body of index.php
  while( list($key, $value) = each ($links_hash) ) {
    echo( &quot;&lt;p&gt;&lt;a href=\&quot;#top\&quot; name=\&quot;$key\&quot;&gt;&lt;b&gt;$key&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;\n&quot; );
    sort ( $value );
    for ( $x=0; $x &lt; count($value); ++$x ) {
      echo( &quot;$value[$x]&lt;br&gt;\n&quot; );
    }
  }
?&gt;
</pre>
<p><a href='http://aim.johnkeston.com/wp-content/uploads/2007/12/php_problem_set_4.zip'>Download: PHP Problem Set 4</a><br />
1. All PHP problems within a “set” are due by the beginning of class on the next day that the class meets.<br />
2. Answers must be available via links on the OLS or comparable hosting and copied to the drop off drive.<br />
3. Solutions to each problem set will be given during demonstrations on the day that they are due.<br />
4. Grades will be collected during the solution demonstrations by an assigned classmate.</p>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/week-4-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Week 5</title>
		<link>http://aim.johnkeston.com/im3420/week-5-3/</link>
		<comments>http://aim.johnkeston.com/im3420/week-5-3/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 15:39:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/04/week-5-3/</guid>
		<description><![CDATA[Session 1: What if you want to make sure that none of the links you&#8217;re adding to the links file are duplicates? You&#8217;re not going to want the same link in the same page twice and it may be difficult to remember every link that you&#8217;ve added. Here&#8217;s an example of how you can prevent [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Session 1:</strong> What if you want to make sure that none of the links you&#8217;re adding to the links file are duplicates? You&#8217;re not going to want the same link in the same page twice and it may be difficult to remember every link that you&#8217;ve added. Here&#8217;s an example of how you can prevent duplicate links from being added to the flat file:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
    import_request_variables(&quot;gP&quot;);
    // Check for a new category
    if ( $new_category ) {
        $category = $new_category;
    }

    // Make sure $url and $category exist before adding
    if ( $url &amp;&amp; $category ) {
        $links_file = file ( 'links.txt' );
        for( $x=0; $x &lt; count($links_file); ++$x ) {
            $field = explode( &quot;\t&quot;, $links_file[$x] );
            $match = rtrim( $field[1] );
            // Check for duplicate links
            if ( $match == $url ) {
                header( &quot;Location: index.php?message=duplicate link&quot; );
                exit( );
            }
        }
        $links_file = fopen( 'links.txt', &quot;a+&quot; );
        if ( $description ) {
            $new_link = &quot;$category\t$url\t$description\n&quot;;
        }
        else {
            $new_link = &quot;$category\t$url\n&quot;;
        }
        fwrite( $links_file, $new_link );
        fclose( $links_file );
    }
    header( &quot;Location: index.php&quot; );
?&gt;
</pre>
<p><strong>Session 2:</strong> If you have gotten as far as getting the links added while avoiding duplicates and displaying the links organized by category, then it&#8217;s time to add the functionality to delete links. To do this you will need to search through your flat file and re-write the information without the link specified for deletion. Here&#8217;s an example of code which will accomplish this task:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
    // File: drop_link.php
    // Author: John Keston
    // Description: Drop a link from the the links flat file

    import_request_variables(&quot;gP&quot;);
    $message = &quot;Link not found&quot;;

    if ( $drop_url ) {
        $links_file = file ( 'links.txt' );
        foreach( $links_file as $line ) {
            $field = explode( &quot;\t&quot;, $line );
            $field[2] = rtrim( $field[2] );
            if ( !$field[2] ) {
                $field[1] = rtrim( $field[1] );
            }
            if ( $field[1] != $drop_url &amp;&amp; $field[2] != $drop_url ) {
                $new_file[] = $line;
            }
            else {
                $message = &quot;&quot;;
            }
            // Uncomment this line for troubleshooting
            // echo ( &quot;&lt;pre&gt;|$drop_url|$field[1]|$field[2]|\n&quot; );
        }
        $new_links = fopen( 'links.txt', &quot;w+&quot; );
        foreach( $new_file as $link ) {
            fwrite( $new_links, $link );
        }
        fclose( $new_links );
    }
    header( &quot;Location: index.php?message=$message&quot; );
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/week-5-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Week 6</title>
		<link>http://aim.johnkeston.com/im3420/week-6-3/</link>
		<comments>http://aim.johnkeston.com/im3420/week-6-3/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 20:29:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/04/week-6-3/</guid>
		<description><![CDATA[Session 1: The links project is due on Session 2, Week 6. This project and the guestbook project is what will determine your midterm grade, please add any finishing touches before Session 2. Most of you have this included already, but to add a dynamically generated drop down list of categories to the add link [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Session 1:</strong> The links project is due on Session 2, Week 6. This project and the guestbook project is what will determine your midterm grade, please add any finishing touches before Session 2. Most of you have this included already, but to add a dynamically generated drop down list of categories to the add link form use the following code. Make sure that you place the code within the form tags of the add link form:</p>
<pre class="brush: php; title: ; notranslate">
&lt;select name=&quot;category&quot;&gt;
&lt;?
    while ( list($key,$value) = each($links_hash) ) {
        echo( &quot;&lt;option value=\&quot;$key\&quot;&gt;$key&lt;/option&gt;\n&quot; );
    }
    reset( $links_hash );
?&gt;
&lt;/select&gt;
</pre>
<p>To turn in the links project, on the drop off drive (Z:/John Keston/mm2421/&lt;yourname&gt;/links) place the following:</p>
<ol>
<li>An Internet Shortcut to your &#8220;links&#8221; project</li>
<li>All the source code</li>
<li>The &#8220;links.txt&#8221; flat file</li>
<li>Add at least 5 categories with a total of at least 20 links to your page</li>
<li>Add some personal design choices to your links page</li>
</ol>
<p>The next project is called the News Database project and involves making a web interface to a remote database. We&#8217;ll use MySQL which is the database platform, and <a href="http://www.phpmyadmin.net/home_page/index.php">PHPMyAdmin</a> as our tool for managing the database. Add the following tables to your student webspace database. Add at least one user with username and password to the users table:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE news_users (
    id          INT PRIMARY KEY AUTO_INCREMENT,
    username    VARCHAR(64)        NOT NULL UNIQUE,
    password    VARCHAR(64)        NOT NULL,
    first_name  VARCHAR(64)        NOT NULL,
    last_name   VARCHAR(64)        NOT NULL,
    email       VARCHAR(128),
    status      VARCHAR(32) DEFAULT 'enabled'
);

CREATE TABLE news_articles (
    id          INT PRIMARY KEY AUTO_INCREMENT,
    headline    VARCHAR(128)        NOT NULL,
    author      VARCHAR(128),
    body        TEXT                NOT NULL,
    create_date DATETIME            NOT NULL,
    modify_date DATETIME,
    user_id     INT                 NOT NULL,
    status      VARCHAR(32) DEFAULT 'enabled'
);
</pre>
<p><strong>Session 2:</strong> The links project is due today. Next step is to write the code which authenticates the user and sets a session cookie so that we know who has authenticated and use their ID to track who&#8217;s creating the news stories. Place these examples in a sub-directory of your php directory called &#8220;news&#8221;. Next create a login form then create a php script called &#8220;auth_user.php&#8221; to compare what the user enters to the database.</p>
<p>1. The &#8220;Login&#8221; form:</p>
<form>
<table border="0" bgcolor="#aaaaaa" cellpadding="3" cellspacing="1">
<tr bgcolor="#FFFFFF">
<td>Username:</td>
<td>
<input name="username" type="text">
      </td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Password:</td>
<td>
<input name="password" type="password"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2">
<input name="submit" value="login" type="submit">
      </td>
</tr>
</table>
</form>
<pre class="brush: php; title: ; notranslate">
&lt;?
    ////////////////////////////////
    // Script Name: auth_user.php //
    ////////////////////////////////
    import_request_variables(&quot;gp&quot;);

    // Connect to a MySQL database
    $dbh = mysql_connect (&quot;localhost&quot;, &quot;jck362aii_jck&quot;, &quot;abc123&quot;)
        or die ('I cannot connect to the database.');
    mysql_select_db (&quot;jck362aii_news&quot;);

    // Build the database query
    $query = &quot;SELECT * FROM news_users WHERE &quot;;
    $query .= &quot;username = '$username' AND &quot;;
    $query .= &quot;password = MD5('$password') AND &quot;;
    $query .= &quot;status = 'enabled'&quot;;
    // Execute the query and fetch the results
    $result = mysql_query($query);
    $row = mysql_fetch_array($result);
    // check for a match
    if ( $row ) {
        // Set a cookie and display the add news form
        setcookie( &quot;user_id&quot;,$row['id'] );
        header( &quot;Location: add_news.php&quot; );
        exit();
    }
    // Return to login.php and displays auth failed message
    header( &quot;Location: login.php?&quot; .
            &quot;message=Authorization failed. Please try again.&quot; );
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/week-6-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Week 7</title>
		<link>http://aim.johnkeston.com/im3420/week-7-3/</link>
		<comments>http://aim.johnkeston.com/im3420/week-7-3/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 03:45:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/04/week-7-3/</guid>
		<description><![CDATA[Session 1: Once you have database authentication working create the add_news.php script which will check to make sure that the user_id cookie has been written and if so display the &#8220;Add News&#8221; form similar to what&#8217;s below. At the top of the form document insert the PHP code below to test for the cookie value. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Session 1:</strong> Once you have database authentication working create the add_news.php script which will check to make sure that the user_id cookie has been written and if so display the &#8220;Add News&#8221; form similar to what&#8217;s below. At the top of the form document insert the PHP code below to test for the cookie value.</p>
<p>The &#8220;Add News&#8221; form:</p>
<table bgcolor="#aaaaaa" cellspacing="1" cellpadding="3">
<tr bgcolor="#ffffff">
<td>Headline:</td>
<td>
<input name="headline" type="text"></td>
</tr>
<tr bgcolor="#ffffff">
<td>Topic:</td>
<td>
<input name="topic" type="text"></td>
</tr>
<tr bgcolor="#ffffff">
<td height="27">Author:</td>
<td>
<input name="author" type="text"></td>
</tr>
<tr bgcolor="#ffffff">
<td>Date:</td>
<td>
<input name="create_date" type="text"></td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">Body:<br />
      <textarea name="body" cols="40"></textarea>
    </td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
<input name="submit" value="Submit" type="submit"></td>
</tr>
</table>
<pre class="brush: php; title: ; notranslate">
&lt;?
  $user_id = $_COOKIE['user_id'];
  if ( !$user_id ) {
    header( &quot;Location: login.php?message=Login before adding news&quot; );
    exit();
  }
?&gt;
</pre>
<p>Now that we are authenticating the administrative users and creating a cookie, we need to send them to the news form so they can add a news story. Here&#8217;s an an example of code we can use to insert a record into the news table:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
  //////////////////////////////////
  // Script Name: insert_news.php //
  //////////////////////////////////

  import_request_variables(&quot;gP&quot;);
  $user_id = $_COOKIE[&quot;user_id&quot;];
  if ( !$user_id ) {
    header( &quot;Location: login.php?message=Login before adding news&quot; );
    exit();
  }

  // Connect to a MySQL database
  $dbh=mysql_connect (&quot;localhost&quot;, &quot;mydb_account&quot;, &quot;mydb_password&quot;)
      or die ('I cannot connect to the database.');
  mysql_select_db (&quot;mydb_name&quot;);

  // Build the database query
  $query  = &quot;INSERT INTO jck_news &quot;;
  $query .= &quot;(headline,author,body,create_date,user_id,status) &quot;;
  $query .= &quot;VALUES &quot;;
  $query .= &quot;('$headline','$author','$body',&quot;);
  $query .= &quot;'$create_date',$user_id,'$status')&quot;;

  // Execute the query and check for validity
  if ( mysql_query($query) ) {
    header(&quot;Location: add_news.php?message=Thanks for your submission&quot;);
    exit();
  }
  echo( &quot;insert failed: $query\n&quot; );
?&gt;
</pre>
<p><strong>Session 2:</strong> Today let&#8217;s discuss how we can take frequently used code and put it into includes. Includes work like functions and are reusable chunks of code that we can link in our PHP documents, rather than re-writing things repeatedly.</p>
<p>connect_inc.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
  // Connect to a MySQL database
  $dbh=mysql_connect (&quot;localhost&quot;, &quot;mydb_account&quot;, &quot;mydb_password&quot;);
  mysql_select_db(&quot;mydb_name&quot;);
?&gt;
</pre>
<p>Use the following line of code to include the connection script in a diferent PHP document:</p>
<p>include(&#8220;connect_inc.php&#8221;);</p>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/week-7-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Week 8</title>
		<link>http://aim.johnkeston.com/im3420/week-8-3/</link>
		<comments>http://aim.johnkeston.com/im3420/week-8-3/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 03:54:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/04/week-8-3/</guid>
		<description><![CDATA[Session 1: Now we can move on the the &#8220;front-end&#8221; of the application. This is where users can view news that has been inserted into the database. The first page will list all the news stories in the database as links and the links for each story will display the details of the story. Here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Session 1:</strong> Now we can move on the the &#8220;front-end&#8221; of the application. This is where users can view news that has been inserted into the database. The first page will list all the news stories in the database as links and the links for each story will display the details of the story. Here&#8217;s the code for the list of stories (show_headlines.php):</p>
<pre class="brush: php; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Show Headlines&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h3&gt;News Stories&lt;/h3&gt;
&lt;b&gt;&lt;font color=&quot;red&quot;&gt;&lt;? echo $message ?&gt;&lt;/font&gt;&lt;/b&gt;
&lt;table&gt;
&lt;tr&gt;&lt;th&gt;Headline&lt;/th&gt;&lt;th&gt;Author&lt;/th&gt;&lt;th&gt;Date&lt;/th&gt;
&lt;?
    /////////////////////////////////////
    // Script Name: show_headlines.php //
    /////////////////////////////////////

	include('connect_inc.php');

    $query  = &quot;SELECT *,DATE_FORMAT(create_date,'%W, %M %D, %Y') &quot;;
    $query .= &quot;AS pretty_date &quot;;
    $query .= &quot; FROM news_articles WHERE status = 'enabled' &quot;;
    $query .= &quot;ORDER BY create_date DESC &quot;;

    $results = mysql_query($query);
    while( $row = mysql_fetch_array($results) ) {
        // create alternating background colors
        ++$x;
        $bgcolor = &quot;#ffffff&quot;;
        if ( $x % 2 ) {
            $bgcolor = &quot;#cccccc&quot;;
        }
        // display the headlines in html table rows
        echo (&quot;&lt;tr bgcolor=\&quot;$bgcolor\&quot;&gt;\n&quot;);
        echo (&quot;&lt;td&gt;&lt;a href=\&quot;show_news.php?id=&quot;.$row[id].&quot;\&quot;&gt;&quot;);
        echo (&quot;$row[headline]&lt;/a&gt;&lt;/td&gt;\n&quot;);
        echo (&quot;&lt;td&gt;$row[author]&lt;/td&gt;\n&quot;);
        echo (&quot;&lt;td&gt;$row[pretty_date]&lt;/td&gt;\n&quot;);
        echo (&quot;&lt;/tr&gt;&quot;);
    }
?&gt;
&lt;/table&gt;
&lt;/html&gt;
</pre>
<p>Challenge: Try to make the column header work as links to sort by that column. Also, clicking twice makes the sort direction change from ascending (ASC) to descending (DESC). Click here for an example.</p>
<p>News Project Milestone #1<br />
1. Login with session authentication is working<br />
2. check_auth.php verifies administrative user (add_news and insert_news)<br />
3. Adding news articles is working<br />
4. show_headlines.php is working</p>
<p><a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format">MySQL Documentation for the DATE_FORMAT function</a></p>
<p><strong>Session 2:</strong> Now we need to write the script called &#8220;show_news.php&#8221; which will display the entire news story. The first part of the script is PHP and the latter part is mostly HTML. What&#8217;s happening is that we are selecting the information from the database and then displaying it in one step.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
  ////////////////////////////////
  // Script Name: show_news.php //
  ////////////////////////////////
  $message = &quot;News story not available&quot;;
  import_request_variables(&quot;gP&quot;);
  if ( !is_numeric($id) ) {
    header( &quot;Location: show_headlines.php?message=$message&quot; );
    exit();
  }
  include('connect_inc.php');

  $query  = &quot;SELECT * FROM jck_news &quot;;
  $query .= &quot;WHERE id = $id&quot;;
  $results = mysql_query($query);

  $row = mysql_fetch_array($results);
  if ( !$row ) {
    header( &quot;Location: show_headlines.php?message=$message&quot; );
    exit();
  }
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h2&gt;&lt;?= $row['headline'] ?&gt;&lt;/h2&gt;&lt;b&gt;
Author: &lt;?= $row['author'] ?&gt;&lt;br&gt;
Date: &lt;?= $row['create_date'] ?&gt;
&lt;/b&gt;
&lt;p&gt;
&lt;?= $row['body'] ?&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/week-8-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Week 9</title>
		<link>http://aim.johnkeston.com/im3420/week-9-3/</link>
		<comments>http://aim.johnkeston.com/im3420/week-9-3/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 04:06:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/04/week-9-3/</guid>
		<description><![CDATA[Session 1: Now our news project is nearly fully functional, but in order to remove or archive news articles we would have to access the database and &#8220;manually&#8221; remove records or change the status of those records. A better solution would be to create a page that allows the user to delete or archive news [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Session 1:</strong> Now our news project is nearly fully functional, but in order to remove or archive news articles we would have to access the database and &#8220;manually&#8221; remove records or change the status of those records. A better solution would be to create a page that allows the user to delete or archive news by pressing a button.</p>
<p>Start by &#8220;re-purposing&#8221; the code that is in place for &#8220;show_headlines.php&#8221; creating a new script in the admin directory called &#8220;modify_news.php&#8221;. Include the code which checks the cookie so that the page is secure and add in forms with hidden variables and buttons to archive and delete the records.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
  // modify_news.php
  // Make sure that the user has authenticated
  $user_id = $_COOKIE[&quot;user_id&quot;];
  if ( !$user_id ) {
    header( &quot;Location: login.php?message=Please login before modifying news&quot; );
    exit();
  }
?&gt;
&lt;html&gt;
&lt;title&gt;Modify News&lt;/title&gt;
&lt;head&gt;&lt;/head&gt;
&lt;font color=&quot;red&quot;&gt;&lt;? echo $_GET[message] ?&gt;&lt;/font&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;Headline&lt;/th&gt;&lt;th&gt;Author&lt;/th&gt;&lt;th&gt;Create Date&lt;/th&gt;&lt;th&gt;Status&lt;/th&gt;
&lt;/tr&gt;
&lt;?
  include(&quot;connect_inc.php&quot;);
  $query  = &quot;SELECT * FROM jck_news &quot;;
  $query .= &quot;ORDER BY status, create_date DESC&quot;;

  $results = mysql_query($query);
  while( $row = mysql_fetch_array($results) ) {
    echo ( &quot;&lt;tr&gt;&lt;td&gt;&lt;a href=\&quot;update_form.php?id=$row[id].\&quot;&gt;&quot; .
           &quot;$row[headline]&lt;/a&gt;&lt;/td&gt;&quot; .
           &quot;&lt;td&gt;$row[author]&lt;/td&gt;&lt;td&gt;$row[create_date]&lt;/td&gt;\n&quot; .
           &quot;&lt;form method=\&quot;post\&quot; action=\&quot;change_status.php\&quot;&gt;&quot; );
    $selected[$row[status]] = ' selected=&quot;selected&quot;';
    echo ( &quot;&lt;td&gt;&lt;select name=\&quot;status\&quot;&gt;&quot; );
    echo ( &quot;&lt;option value=\&quot;enabled\&quot; $selected[enabled]&gt;Enabled&lt;/option&gt;\n&quot; );
    echo ( &quot;&lt;option value=\&quot;disabled\&quot; $selected[disabled]&gt;Disabled&lt;/option&gt;\n&quot; );
    echo ( &quot;&lt;option value=\&quot;archived\&quot; $selected[archived]&gt;Archived&lt;/option&gt;\n&quot; );
    echo ( &quot;&lt;/select&gt;&lt;/td&gt;\n&quot; );
    echo ( &quot;&lt;input type=\&quot;hidden\&quot; name=\&quot;id\&quot; value=\&quot;$row[id]\&quot;&gt;&quot; );
    echo ( &quot;&lt;td&gt;&lt;input type=\&quot;submit\&quot; value=\&quot;Change Status\&quot;&gt;&quot; );
    echo ( &quot;&lt;/td&gt;\n&lt;/form&gt;\n&lt;/tr&gt;\n&quot; );

    // clear the $selected hash
    unset( $selected );
  }
?&gt;
</pre>
<p><strong>Session 2:</strong> Here&#8217;s a good way to build the change_status.php script. Make sure that you remember to replace all the location paths and table names with the appropriate values. This script also uses a function. Functions are way to write code that you can reuse by calling the function.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
  // change_status.php
  // Make sure that the user has authenticated
  $user_id = $_COOKIE[&quot;user_id&quot;];
  if ( !$user_id ) {
    header( &quot;Location: login.php?&quot; .
            &quot;message=Please login before modifying news&quot; );
    exit();
  }
  function update_status ($id, $status) {
    include (&quot;connect.php&quot;);
    $query  = &quot;UPDATE jck_news SET status='$status' &quot;;
    $query .= &quot;WHERE id = $id&quot;;
    return mysql_query($query);
  }
  if ( update_status($_POST[id], $_POST[status]) ) {
    $message = &quot;Set news article $_POST[id] status to $_POST[status]&quot;;
    header (&quot;Location: modify_news.php?message=$message&quot; );
    exit();
  }
  else {
    $message = &quot;Update Failed&quot;;
    header (&quot;Location: modify_news.php?message=$message&quot; );
    exit();
  }
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/week-9-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Week 10</title>
		<link>http://aim.johnkeston.com/im3420/week-10-3/</link>
		<comments>http://aim.johnkeston.com/im3420/week-10-3/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 04:39:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/04/week-10-3/</guid>
		<description><![CDATA[Session 1: The last step that we&#8217;ll take in the administrative area is building the functionality necessary to allow administrators to completely update a news article in the database via a web form. This will require two scripts the first script will be the form, prefilled, so that the administrator can edit the data, and [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Session 1:</strong> The last step that we&#8217;ll take in the administrative area is building the functionality necessary to allow administrators to completely update a news article in the database via a web form. This will require two scripts the first script will be the form, prefilled, so that the administrator can edit the data, and the second (standalone) script will include the UPDATE query. Here&#8217;s the source for the first script:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
  // update_form.php
  // Make sure that the user has authenticated
  $user_id = $_COOKIE[&quot;user_id&quot;];
  if ( !$user_id ) {
    header( &quot;Location: login.php?message=Please login before updating news&quot; );
    exit();
  }
  if (!$_GET[id]) {
    header( &quot;Location: modify_news.php?message=No such news article&quot; );
    exit();
  }
  // Connect to database
  include (&quot;connect.php&quot;);
  // Build query
  $query = &quot;SELECT * FROM jck_news WHERE id = $_GET[id]&quot;;
  $result = mysql_query( $query );
  if (!$result) {
    header( &quot;Location: modify_news.php?message=Query failed: $query&quot; );
    exit();
  }
  $row = mysql_fetch_array( $result );
  $selected[$row[status]] = &quot;SELECTED&quot;;
?&gt;
&lt;html&gt;
&lt;title&gt;Update News Article&lt;/title&gt;
&lt;head&gt;&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;update_news.php&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;&lt;? echo $row[id] ?&gt;&quot;&gt;
Headline:
&lt;input type=&quot;text&quot; name=&quot;headline&quot; value=&quot;&lt;? echo $row[headline] ?&gt;&quot;&gt;&lt;br /&gt;
Author:
&lt;input type=&quot;text&quot; name=&quot;author&quot; value=&quot;&lt;? echo $row[author] ?&gt;&quot;&gt;&lt;br /&gt;
Create Date:
&lt;input type=&quot;text&quot; name=&quot;headline&quot; value=&quot;&lt;? echo $row[create_date] ?&gt;&quot;&gt;&lt;br /&gt;
Status:&lt;br /&gt;
&lt;select name=&quot;status&quot;&gt;
&lt;option value=&quot;enabled&quot;&lt;?= $selected[enabled] ?&gt;&gt;Enabled&lt;/option&gt;
&lt;option value=&quot;enabled&quot;&lt;?= $selected[disabled] ?&gt;&gt;Disabled&lt;/option&gt;
&lt;option value=&quot;enabled&quot;&lt;?= $selected[archived] ?&gt;&gt;Archived&lt;/option&gt;
&lt;br /&gt;
&lt;textarea name=&quot;body&quot;&gt;&lt;? echo $row[body] ?&gt;&lt;/textarea&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; value=&quot;Update&quot;&gt;&lt;input type=&quot;reset&quot; value=&quot;Reset&quot;&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>Session 2:</strong> Finally we need the script which actually updates the record in the database. We will call this standalone PHP script update_news.php as it is called in the form action in update_form.php. Here&#8217;s the source for update_news.php:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
  // update_news.php
  // Make sure that the user has authenticated
  $user_id = $_COOKIE[&quot;user_id&quot;];
  if ( !$user_id ) {
    header( &quot;Location: login.php?message=Please login before updating news&quot; );
    exit();
  }
  // Connect to database
  include (&quot;connect.php&quot;);
  import_request_variables(&quot;gP&quot;);
  // Build query
  $query  = &quot;UPDATE jck_news SET headline='$headline', &quot;;
  $query .= &quot;author='$author', create_date='$create_date', &quot;;
  $query .= &quot;modify_date=NOW(), body='$body', status='$status', &quot;;
  $query .= &quot;user_id=$user_id WHERE id=$id&quot;;

  if ( mysql_query($query) ) {
    header( &quot;Location: modify_news.php?message=News article id: $id updated.&quot; );
    exit();
  }
  header( &quot;Location: modify_news.php?message=Update failed: $query&quot; );
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/week-10-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Week 11</title>
		<link>http://aim.johnkeston.com/im3420/week-11-3/</link>
		<comments>http://aim.johnkeston.com/im3420/week-11-3/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 04:48:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IM3420 Advanced Scripting Languages]]></category>

		<guid isPermaLink="false">http://aim.johnkeston.com/2007/12/04/week-11-3/</guid>
		<description><![CDATA[Session 1: Today we will be reviewing for the final quiz. Afterwards in the studio, let&#8217;s add some final touches to the news project. Early presentations of the news project are acceptable as well. Session 2: The final quiz is today. Afterwards we will discuss the questions and then present the news projects.]]></description>
			<content:encoded><![CDATA[<p><strong>Session 1:</strong> Today we will be reviewing for the final quiz. Afterwards in the studio, let&#8217;s add some final touches to the news project. Early presentations of the news project are acceptable as well.</p>
<p><strong>Session 2:</strong> The final quiz is today. Afterwards we will discuss the questions and then present the news projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://aim.johnkeston.com/im3420/week-11-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

