Updated 1/7/2020 at 7:30pm
Homework #9: SQL Queries
-
Remember to follow all the standard Homework Requirements.
- This assignment will demonstrate:
- Adding a form to your Products page;
- Using a query to populate/build a select list in the form.
- Main steps in this assignment:
-
Highlight, copy, and paste the config.php sample code from the e-handout section "The config.php File",
into your editor. Put your login information and database name into it.
Save it as (no surprise here) config.php.
- Add an HTML form to your Products page, to accept data for your
Products table.
Use standard HTML <input> fields to accept the
data that the user types to add to your Products table. (There are some HINTS below, regarding
where to put this second form in your Products page.)
-
The above requirement means that you will have standard (<input type="text">) tags in
your form to accept information for these fields in the Products table:
- Name
- Color
- UPC
- Quantity_In_Stock
- Wholesale_Price
- Retail_Price
- (Supplier ID -- but see below...)
-
However, the SupplierID field in the Products table will need to contain a valid
SupplierID from the Suppliers table. The best way to make sure the value
is valid is to allow the user to select a supplier from a select list.
Therefore, your form will need to also include an HTML <select> list
of suppliers. Use a SQL Select statement (and a PHP query, of course)
to build/populate the select list. See below for some hints regarding
how to populate the list.
-
IMPORTANT:
You will NOT make the action code for this assignment.
The action code for this form will be the code that you
make for the next assignment.
-
Upload your Products page to your class Web site.
-
Test your page on the PHP Web server by clicking your student number on the
"Student Sites" page of this class site. Display your Products page. Make sure
the Products page displays the correct form, and make sure the "Supplier" select list
has your supplier(s) in it.
-
Here are some HINTS regarding using a query to build/populate an HTML
Select list:
-
A good page to use as your template and/or guide is the code in the previous class's e-handout section
"Populating a Select List - Single Page", which is selectMemo2.php.
It has just about everything you need for your select list. But you will still need to add
the other form input fields. (See above for the input fields that you need.)
-
You only need to query (select) the fields that you want from the Suppliers
table. You should only need SupplierID and Name.
-
The action code will need the SupplierID.
Therefore, the SupplierID should be the value attribute's value in
each <option> tag in your select list.
-
The user will want to pick a supplier by name, however, so the Name
field from the query that gets SupplierID and Name from the Suppliers table should
be used as the displayable text portion of each <option>...</option> tag.