CS 207 - PHP Lab 2
Friday, 25 January 2019
To give scope to your lab exercises in this class, you need to
imagine or invent or use some actual, organization or business.
It could be a recreational trail, an online seller of electronic
gadgets, a hockey league, a singer-songwriter's fan club, a student
newspaper, tours to the moon, etc.
This week you can create just one table, next week
you need to create at least a second table that can be
"joined" with the first.
You want to be able to implement a variety of database actions,
including searching, adding and modifying data, for example:
- Allow people to get on your mailing list, possibly with
categories like new products, gas-fired barbecues, trail conditions,
event cancellations, or volunteer opportunities.
- Viewing products, or a selection of products. Game schedules for
a particular team, or location.
- Ordering something: a "Dick Tracy" 2-way wrist radio, a T shirt, a VIA
rail train hat or whistle.
- Record the sighting of a turkey in your crab apple tree
- Posting news items - for administrators only.
- Seeing the latest news, or all the current sports news (a
category) - by the public.
- Maintain an inventory of what's available. To sell, or tools
available for volunteers....
What to do this week in the lab:
Insert data into a table you create. You will need to define the
table, and create a form in which to enter one row of data for it. A form you created during CS 203, or the
one you created last week, may be suitable for this. If not, you
need to create one today. (see below)
receive credit for this lab, your database must contain a table, with
data in it entered from the form. I should be able to enter more.
- A database named for your username is set up on Osiris.
- Defining one or more tables. (CREATE TABLE statement, and ALTER
TABLE as need arises.) If necessary, look at the tutorial at
postgresql.org and other documentation
- In a Terminal,
no database login or password required, you are connected to
your own database on Osiris
- Grant permissions for user apache,
this is necessary for your scripts to work. For example:
grant connect on database yourdb to apache;
GRANT SELECT, INSERT ON customers, products TO apache;
- CREATE TABLE ... and if necessary, ALTER TABLE...
- Writing a php page (file) that inserts the new data from your
form into your database. When you think it "works",
- Go back to psql and do select * from yourtble;
to be sure that the data is there.
Testing method this week:
- I will enter test data.
- I will use psql to look at your database, and need to find my
test as well as yours.
What you may have done previously:
I need to be able to find your work on Osiris, easily. It may be that
this will grow naturally out of what you did last semester, you already
have a form for people, and this is what you will use to start building
your database. Otherwise, you may end up creating a new set of pages, I
would prefer this to be the first thing I see, proceed as follows:
- Create the main page for
your organization, describing it. Put your new page on Osiris, in your
directory named www
- If you have an existing "Home page" on Osiris, either
If you skipped cs 203, you are
starting fresh (so ignore #2), and might need to look at some of the
early lab instructions for that course.
Include on Osiris a form,
allowing the public to (for instance) join your mailing list.
- rename it, and link to
it from your new page (perhaps " maintained by ... ) and name your new
page index.html. or
- Put a prominent link to your new page at the top of your existing html.
- It is generally not a good
idea to allow the public to both enter information, and also be able to
view it, as this invites the equivalent of "spam"
Tell me that you are done, and what you did:
What to expect next week:
- Add ability to update existing data, such as change of address....
- One or more additional tables. For example, a customer ordering a
book or other product. Or a reader commenting upon an editorial.
- Pages allowing this to happen.