Database lab 10

Overview

The purpose of this simple lab is to prepare the student to develop and write PHP programs. First we will learn how to write code on our local machine, copy it to a web folder, and view it. Then we will write a simple program to calculate loan repayments.

Preparation

This lab assumes you are able to understand and make modest changes to PHP code. If you find this task daunting, it is suggested that you go through one or more of these tutorials first:

PHP coder checker

Another resource you will find useful is phpcodechecker. You can copy and paste your php code into it, and it will tell you if your code has syntactic issues.

phpcodechecker.png

Turning in your work

As you do this lab, make a single word document. Number the steps, and in order paste into the document links to the result of each step, as well as the code you produce. Put in comments to clarify, or to describe problems you had.

Step 1 - accessing the CS system

Using the CS server

The CS server has address cs.mvnu.edu. It is a Ubuntu Linux server running on the server array in the Libaray. We will be using this to host our SQL Relational Database Server (mySQL), our web server, and the programs that we write in PHP, HTML, and SQL.

Each Student has an account that you used in previous labs.

On the server you will have a folder for your use at /home/students/username. (User your username). This is your main work area where you can store personal documents. However, the files and programs you will make available to the web server need to be in the web accessable area. On the CS system all web documents are stored in a folder starting at /var/www. We call this the "web server root" folder. In this folder there is subfolder for this course located at /var/www/classes/csc3031/. Inside that is a demo folder, along with a subdirectory there with your username. This is where ALL of your publicly (web) available web documents and programs will need to be.

The image below depics part of this folder tree:

FolderTree_.png

Using PuTTY

PuTTY is a program that allows you to login to the server, and manipulate it using text commands. using it we can manipulate and edit files on the server to create and change the programs and web services we wish to use. If you want, you can create and edit your work using text editors like emacs, and move files around using commands like cp, rm, mkdir, etc, or you can use one of the solutions below.

Go to Commands, and select Open in PuTTY . Then login using the user name and password.

PuTTY terminal program:

Putty.png

In the terminal program to do a cd /var/www/classes/csc3031/yourusername This is where you will place file for web browser access (this is "in" the www file tree). I have already put some files in your directory for you. DO an ls command to see the files. Now use a web browswer to go to http://cs.mvnu.edu/classes/csc3031/. You will see a file list that includes you name. The list will match what you saw from the ls command.

Click on several of the php programs to try them out.

File Transfer

On a lab computer, go to All Programs from the Start menu, and select WinSCP (directory), then WinSCP (program).

SCP Main Screen:

scpmain.png

This brings up a secure file transfer program. Enter in cs.mvnu.edu for host name, and your username in the username field. Finally enter your password into password field.

This brings up the file transfer window.

SCP File Screen:

SCPFile.png

Here you can see files on your local system on the left, and file on the CS server on the left. You can move files back and force merely by dragging them.

In practice, this is most of what we need for this course. We can simply edit all your programs, scripts and web pages on our favorite operating system, then copy them to the CS server to try them out. Try hello.exe, hello2.exe, math.exe. You can also try the others.

Step 2 - transfering and modifying php code

Us the SCP program to copy the files in your web folder to your local system. Open them up with notepad (or your favorate text editer) and see the code! Modify hello.php to display todays weather report, and change to name to weather.php. (Just go to a weather page, and copy and paste the weather). Copy it back out to the server, and try it out. Remember to use the code checker if you have a problem.

Now edit hello2.php.. How is it different? Change this to use variable(s) to describe todays weather, and save as weather2.php

Step 3 - Building you own form based program

This step is worth 80 points out of 100 for this lab. Because there are students in here at multiple levels, what you must do to get the 80% is based on you level. Do enough steps to get 80 points, or more!

Try out the following code:

  • math.php
  • acmeform.html, acemprocessorder.php (Notice here you start with acmeform.html which calls acemprocessorder.php to process what you enter. a button brings you back to acmeform.html.
  • artorder.html, artprocess.php (similar to above)
Copy the programs above from your web folder. Then use them as a base (with a different file name) to do the following to get points, depending on your level:

Software Development

Program CS I CS II Soft
Dev
A simple calculator with +, -, *, /, squareroot, mod, and exponentiation. Use the pull downs menu to select functions like in math.php 40 30 10
Modify the ACME order program to include a price for each item. Also add 3 more items to the list to select from. When the order is processed, show the subtotal for type of item ordered, and then a total for the order. 40 30 10
Modify the artorder program to instead list all the available items (rather than the pulldown), but make a pulldown for the number of items to order (from 0 to 10), Add prices to the items, and on result page show the subtotal for type of item ordered, and then a total for the order. 40 30 10
Create a program to compute the day of the week given a month, day, and year. The algorithm can be found here: http://h2g2.com/approved_entry/A22548314 80 60 40

Make a loan calculator. You enter the following

  1. loan amount in dollars
  2. the duration of the loan in years as a pulldown (5, 10, 15, 20, and 30 years)
  3. the down payment in dollars
  4. the interest rate (use a pulldown, allowing the rates from 3% to 6% in .25% increments)

Calculate:

  1. total simple interest paid over the total number of years
    interest = (priceOfHome - downPayment) * interestRate * years
  2. total price of the home
    totalPrice = priceOfHome + interest
  3. monthly payments
    Assume the total amount is paid back evenly distributed over the entire number of months

80 60 40

Augment the loan calculator to print a load amortization table. This means you show for each month you show:

  1. Payment
  2. Principal Paid
  3. Interest
  4. TotalBalance

Here is a link to how to do the calculations: http://www.hughchou.org/calc/formula.php

Here is an example: http://www.bankrate.com/calculators/mortgages/amortization-calculator.aspx

80 60 40

Create a program to do base conversions. Given:

  1. a number
  2. a base for the number (2, 8, 10, 16)
  3. a target base (2, 8, 10, 16)

Give the number in the target base.

Error check your inputs for proper base (e.g. of they select base 2, and enter 101131 for the number to convert, it should tell the user the number entered is not a value base 2 number.

140 100 80

Step 4

Turn in your results

On Moodle, turn in a link to your word document.

-- JimSkon - 2011-09-09

  • phpcodechecker.png:
Topic attachments
I Attachment Action Size Date Who Comment
Pngpng FolderTree_.png manage 15.3 K 2013-11-15 - 13:02 JimSkon  
Pngpng phpcodechecker.png manage 98.7 K 2013-11-15 - 13:34 JimSkon  
Topic revision: r4 - 2013-12-15 - JimSkon
 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback