You will recall that the action property of our new product form contained a property of "action='new_product_preview'. If you have been using osCommerce for any length of time, and I assume you have otherwise you probably wouldn't be reading this article, you know that when adding a new product after all the data is entered you click on a 'Preview' button, you are then taken to a review page. However it's not a complete preview, the preview only shows a few pieces of information such as the item title, description, image, and price.
If I haven't said so before and if I have it's worth saying again, the categories.php file is very long and complex. Fortunately Dreamweaver, my favorite PHP/HTML editor, has a handy find and replace tool. Performing a search on 'new_product_review', I find on line 596 the following:
} elseif ($action == 'new_product_preview') {
This just happens to be the 'elseif' for the 'if' that initially loaded our form. The page is self posting, so again the first time through the form is loaded and the second time through we load the preview presentation. All of this is accomplished by changing the action parameter and simply running a different section of code each time. If we browse through the code below line 596 we may see the code is dealing with the gathering and display of items which appear on the preview page. Our new sample file field is not a part of the preview, so we don't need to be too concerned just yet. However there is something interesting on line 610:
$form_action = (isset($HTTP_GET_VARS['pID'])) ? 'update_product' : 'insert_product';
It's beginning to look like categories.php is even more polymorphic than we could have imagined. Line 610 is setting the action property for the form which is the preview page. What we see here is form of 'IF" statement short hand. The syntax goes something like this:
$var = (some condition) ? if true $var = this : if false $var=this
In other words $var will be equal to the value after the '?' if the condition is true or it will be equal to the value after the ':' if the condition is false. What line 610 is saying is if the pID exists we are going to perform an update of the product. However if there is no pID then we have a new product so therefore we are going to do an insert. Browsing through the remaining code down to the form end tag confirms we do not have to code anything for our new field at this point.
As far as we are concerned this is not a situation of 'either/or' because we will need to deal with both conditions, we will need to have the capacity to work with the new sample field when we create a product and later if we happen to want to update it. Follow the natural progression we'll start with 'insert_product'.
Performing a text search for 'inset_product' look what we find on line 205:
case 'insert_product':
I told you we would get back to the case statements eventually, and the time is now. A quick note here, you might be thinking, we were down at line 610 how did we get all the way back up to line 205? Well remember each time we click a submit button, the page posts back to itself and we start at the top again. So we know from the discussion in part 3 that when we find a case condition that is true, the code below it until we hit 'break' will be executed. An look what we find on line 206:
case 'update_product':
That's right, it appears that we are only going to have to work with one block of code for both the insert and the update, that's a nice little relief. We are getting closer and closer to having our project complete and that's always a good feeling. Moving forward we skip down to line 215 to 222:
$sql_data_array = array('products_quantity' => tep_db_prepare_input($HTTP_POST_VARS['products_quantity']),
'products_model' => tep_db_prepare_input($HTTP_POST_VARS['products_model']),
'products_price' => tep_db_prepare_input($HTTP_POST_VARS['products_price']),
'products_date_available' => $products_date_available,
'products_weight' => tep_db_prepare_input($HTTP_POST_VARS['products_weight']),
'products_status' => tep_db_prepare_input($HTTP_POST_VARS['products_status']),
'products_tax_class_id' => tep_db_prepare_input($HTTP_POST_VARS['products_tax_class_id']),
'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id']));
As it turns out this is the only section in this block of code and the last in categories.php we will need to modify. However I want to explain a couple of things. The above section of code is adding most of the fields from the new products/update products form to an array, $sql_data_array. The function 'tep_db_prepare_input' is another handy funtion built into osCommerce. The function serves to format things into a SQL statement. If you have ever had to write code that generates SQL insert or update statements, you know just how handy it is. Moving down to line 233 we find:
tep_db_perform(TABLE_PRODUCTS, $sql_data_array);
'tep_db_perform is another function which is abstract to us, it takes care of either the insert or update and we don't have to worry about anything else. Ok so lets go back to $sql_data_array, for the sake of simplicity I'm only going to show the last line:
'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id']));
We need to add 'products_sample_file' to this array so once we are done the last two lines will look like this:
'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id']),
'products_sample' => tep_db_prepare_input($HTTP_POST_VARS['[products_sample']));
So now our new sample file field will become part of the array and part of the insert/update statement to the database. And there you have it, we're all done with the admin side of things. However we do have one important step to go, and that is how we are going to display things to our customer who visits our store. We'll cover that in the next and final part of this series.
Happy Coding!

![Add this page to My.MSN.com... Shopping Cart Review - ECommerce Cart Software Reviews, Ratings and Information Understanding osCommerce - Adding a Field Part 4 - [XML/RSS 2.0]](/images/rss_mymsn.gif)
![Subscribe to this page with Bloglines... Shopping Cart Review - ECommerce Cart Software Reviews, Ratings and Information Understanding osCommerce - Adding a Field Part 4 - [XML/RSS 2.0]](/images/sub_modern5.gif)
![Subscribe to this page with NewsGator Online... Shopping Cart Review - ECommerce Cart Software Reviews, Ratings and Information Understanding osCommerce - Adding a Field Part 4 - [XML/RSS 2.0]](/images/ngsub1.gif)
![Subscribe to this page with Feedburner... Shopping Cart Review - ECommerce Cart Software Reviews, Ratings and Information Understanding osCommerce - Adding a Field Part 4 - [XML/RSS 2.0]](/images/fbapix.gif)






















