PHP Programming (Blended)
3 credits
Comments placed the source code file | 5 |
Table data can be viewed and includes picture | 15 |
New records can be added to the table | 25 |
Records can be edited | 25 |
Records can be deleted | 20 |
Forms are easy to use, perform validation, and include defaults | 10 |
Total | 100 pts |
Practice using PHP with MySQL
Biag Raw has approached you with a new problem. He is currently planning on starting a website where he will sell lightsabers. All of the information about the lightsabers that are to be eventually displayed for sale on their website are to be stored in a MySQL database but Biag is concerned that the database will be too difficult to manage if SQL has to be written manually to work with their database.
Mr. Raw would like for you to create a page or set of pages written in PHP that could be used in place of writing SQL to update the database. The solution will need to include a way for the sites operators to see (Read) all of the information currently in the database, to be able to add new lightsabers (Create), to edit listing for lightsabers already in the database (Update), and to delete lightsabers that are no longer being sold (Delete). Images of the lightsabers will be included and should be displayed as images when the table data is viewed. The images should be specified when adding or editing lightsaber listings by filename.
The solution will eventually be used by hired help so everything needs to be easy to use and as intuitive as possible. Any forms used should be validated to the greatest possible extent to ensure that bad data does not get into the database.
Your database designer has consulted with Mr. Raw and has decided that the following tables should be sufficient for the customers needs. You'll need to create the alignments table first followed by the lightsabers table.
Alignments table:
create table alignments ( id int not null auto_increment, description varchar(100) not null, primary key(id) )
insert into alignments (description) values ('Light Side') insert into alignments (description) values ('Dark Side')
Lightsabers table:
create table lightsabers ( id int not null auto_increment, name varchar(50) not null, description text not null, price float not null, image varchar(100) not null default 'images/na.gif', alignment int not null, primary key(id), foreign key(alignment) references alignments(id) )
The Alignments table will change very infrequently if at all so no interface is required for it. Simply insert the two values above so that there will be values which will be needed by the lightsabers table. Remember that the alignment field in the lightsabers table references the id values in the alignments table so one of these id's must be present in any new lightsaber record.