Lab 11


For this lab you will be writing an Admin Poduct Content script that will display an HTML of input fields for the Product's name, image, description, price, rating, sku, and stock. You will also have 5 buttons "Previous", "Update", "Insert", "Delete", and "Next". Set up your form such that it will appear if it were outputted from your previous lab.

 ---------------------------------------
|Img:image      |Name: item_name        |
|    file       |Rating: 5              |
|    name       |Price: $98.76          |
|    item.png   |SKU: 123abc987zyx000   |
|               |Stock: stock_qnty      |
|---------------------------------------|
|Description:                           |
|                                       |
|                                       |
 --------------------------------------- 
<-Prev | Insert | Update | Delete | Next->

text inputs: name,img,sku. textarea: description. number: rating[min0..max5], stock[min0..+inf], price[min0..+inf]

When the page loads for the first time or $_GET['q'] is less than or equal to 0 or NULL, display an empty form. Set a variable 'q' equal to 0. When populating the form, for the "Previous" and "Next" buttons, wrap an anchor tag around the buttons such that the href will contain the full URL to this script followed by "?q=($q + or - 1)".

PREVIOUS / NEXT: When the user clicks on either button the anchor tag will make a GET request passing a value for 'q'. If the q value is 0, display an empty form. Otherwise, perform a select all query, and use mysqli_resut::$num_rows or mysqli_num_rows to get the number of rows in a result. If the 'q' value is less than or equal to zero, or greater than or equal to the number of rows, set 'q' to zero, and display an empty form. Otherwise, use mysqli_result:: data_seek or mysqli_data_seek function that will adjust the result pointer to an arbitrary row in the result. The first row will be at offset 0: when $_GET['q']==1 $res->data_seek($q-1). Fetch the row, and populate the form accordingly.

The insert, update, and delete buttons will all be submit buttons named 'action' with their respective values

INSERT: When the form is submitted via POST and $_POST['action'] is equal to "Insert", validate, that all fields are not empty. Before the insert query, we need to confirm that there are no other products that have the same product sku number. Perform a select query where prod_sku is equal to the form's sku. If the returned result was empty, we can go ahead and insert the data. Sanitize and real escape the data, then perform an insert query. If the query was successful, display to the user that the update was successful and resdisplay an empty form. Otherwise, display a sticky form and *mark the missing fields, and/or state that the insert query was unsuccessful and or state that there already exists a product with the given sku.

UPDATE: When the form is submitted via POST and $_POST['action'] is equal to "Update", validate, that all fields are not empty. Sanitize and real escape the data, then perform an update query and set the values equal to the values via the form, where product's sku is equal to the the value from the form (we'll use the sku as a constraint/where clause for the update). If the query was successful, display to the user that the update was successful and resdisplay an empty form. Otherwise, if there was an empty field or the query was unsuccessful, display a sticky form and *mark the errors and/or state that the query was unsuccessful.

DELETE: When the form is submitted via POST and $_POST['action'] is equal to "Delete", you only need to validate that the sku field is not empty. Sanitize and real escape the posted sku value, then perform a delete query where the product's sku is equal to the value via the form (we'll use the sku, again, as a constraint/where clause). If the query was unsuccessful, display to the user that the delete was unsuccessful and display an empty form.



It could be helpful to use your lab10.php to display all of your product records and check to see if queries were successful.


Name this script lab11.php and include all of your php,css,images,images directory, etc, in your ~/public_html/3680_S19/wk11/ directory (Odin).