RU beehive logo ITEC dept promo banner
ITEC 325
2015fall
ibarland

homelectsexamshws
D2Lbreeze (snow day)

hw04
DB connectivity

Due: 2015.Dec.0108 (Tue) 23:59.
(I highly recommend completing this before Thanksgiving break. However, I'm having it due a day after break completes, to give you a chance to come by office hours. Also, I'll be monitoring the discussion boards over the break.) Am accepting it through Dec.08 only because I goofed up and set that on D2L.

You will complete your new-Okaymon page by storing the okaymon in a database, and retreiving a summary list of all Okaymon.

  1. Your page at https://php.radford.edu/~yourUserId/itec325/hw04/index.php should have a link to:

    Submit your files on D2L (individually, not as a jar).

  2. (40%) Modify the ol' Okaymon form handler so that once the information is validated, the Okaymon is added to the database.

    You can create your database through SQL statements (preferred), or through the GUI interface at MySQL Admin . In either case, include SQL statement(s) which CREATE your tables; you can use MySQL Admin's feature to show this statement. Place the statement in a file “okaymon-db-create.sql”.

    As discussed in lecture, be sure to guard against SQL injection — either by calling mysqli_real_escape_string on any user-provided text which becomes part of a SQL query, or (preferred, but not required) via prepared-statements. (Do this even if other validation requirements make such escaping moot.)

    Make sure you that you can insert/retrieve values that have “SQL-sensitive” characters like apostrophes, spaces, and semicolons (as well as the “html-sensitive” characters like less-than and ampersand that we've already handled). Automate this testing by adding/modifying your demo-forms to include such characters.

  3. (30%) Make a page which shows a summary list of all Okaymon previously entered: just the Okaymon name, the associated energy-type, and the weight. This page should also include a link to the Okaymon-entry-form page. (It does not need to be particularly pretty — just loop over the results of the database query.)

    Be sure all your pages/programs always close any database connection they open!

  4. (30%) Each Okaymon-name on the summary list should be a link which, when clicked, brings you to a detailed-information page that includes the previous information plus the full description and who submitted the Okaymon.

    (The layout of this information does not need to be anything elegant, but it should not be prone to HTML/script injection.)

    Pro tip:

    From hw03 on, you already have a page which prints the summary information (on a successful submit); it used $_POST.

    You can re-factor that page so that instead of reading from $_POST, it reads from some other array, say, “$the-Okaymon-info”. Then:

    • To get the old behavior, $the-Okaymon-info = $_POST; followed by require("print-Okaymon-info.php");.
    • To meet this new requirement for this hw, read the database-info for a Okaymon into $the-Okaymon-info, and then you can just require("print-Okaymon-info.php"); from there!
    Adding a layer of indirection: is there any problem it can't solve?

    Note that this is asking for a link which behaves a little bit like a form-handler, since you won't have a separate URL for every single Okaymon — instead you'll have one page which (given a particular Okaymon-name) pulls the detailed information out of the database. How do you have a link which provides an argument (Okaymon-name) to another page? One easy way1 is to have the link contain the parameter(s) explicitly, e.g.<a href="Okaymon.php?okaymonName=pugglez">…”, and the receiving page accesses that argument through the $_GET array (e.g., $_GET['okaymonName']).

    As always, to guard against HTML/script injection, be sure to call htmlspecialchars on any text which was originally provided by a user (even if retrieved from the database). (This goes for all pages, even if other validation requirements make such escaping moot).

    You don't need to include the Okaymon's energy-biases on this page. If you do, it's extra-credit worth 5% of this homework.

  5. I'll say it again, just because it's fun: Be sure all your pages/programs always close any database connection they open!

Guidelines


1

Transmitting the arguments through $_GET of course is vulnerable to over-the-shoulder snooping; if you wanted to still use $_POST but not require a “submit” button, you can set the link's onclick attribute to be javascript which (a) sets the value of a hidden input tag, and then (b) does something like document.getElementByID( 'theFormsId' ).submit().

     

homelectsexamshws
D2Lbreeze (snow day)


©2015, Ian Barland, Radford University
Last modified 2015.Nov.30 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.