hello zen-cart guru

i tried to solve my problem with delivery control mod,
sadly i have limited knowledge of php
i tried to look at the script.

i found these code in the script in delivery_new.php

PHP Code:
if($action == "add"// ADD PRODUCT DELIVERY !!!
{                   
   ...            
   ...
   ...

   if(
$step 3)
   {
      
//test if record exist
      
$exist $db->Execute("select prod_quantity AS quantity
                             from delivery_products
                             where del_id = '"
.$dID."' 
                             and prod_id = '"
.$add_product_products_id."' ");

   

      
$action='update';

      echo 
"<tr class=\"dataTableRow\">
       <form action='
$PHP_SELF?dID=$dID&action=$action' method='POST'>\n";
           echo 
"<td class='dataTableContent' align='right'><b>STEP 3:</b></td>";
           echo 
"<td class='dataTableContent' valign='top'>
             <input name='add_product_quantity' size='5' value='1'>" 
ADDPRODUCT_TEXT_CONFIRM_QUANTITY "</td>
         <td align='center'><input type='submit' value='" 
ADDPRODUCT_TEXT_CONFIRM_ADDNOW "'></td></tr>";

      echo 
"<tr><td></td><td class='dataTableContent' valign='top'></td>";
         if (
$exist->RecordCount() > 0) {
            
//record exist!
            
echo ('<tr><td></td>
            <td><font color="red">Product exists and it\'s quantity will be updated!</font>
            <br>
            <i>Original quantity: ' 
$exist->fields[quantity] . '</i>
            </td>
            <td></td></tr>'
);
            echo 
"<input type='hidden' name='exist' value='yes'>";

         }


      echo 
"<td>";

      if(IsSet(
$add_product_options))
      {
         foreach(
$add_product_options as $option_id => $option_value_id)
            {
               echo 
"<input type='hidden' name='add_product_options[$option_id]' value='$option_value_id'>";
            }
      }
   
      echo 
"<input type='hidden' name='add_product_categories_id' value='$add_product_categories_id'>";
      echo 
"<input type='hidden' name='pID' value='$add_product_products_id'>";
      echo 
"</td>\n";
      echo 
"</form></tr>\n";
   }

   echo 
"</table>\n";
   echo 
'<br><center><a href="' zen_href_link(FILENAME_DELIVERY'dID='.$dID'NONSSL') . '">' zen_image_button('button_cancel.gif'IMAGE_CANCEL) . '</a></center>';


and these code on top of the delivery_new.php, and i copied to a file named test.php

PHP Code:
require('includes/application_top.php');

$action = (isset($_GET['action']) ? $_GET['action'] : '');
$pID zen_db_prepare_input($_POST['pID']);
$dID zen_db_prepare_input($_GET['dID']);
$exist zen_db_prepare_input($_POST['exist']);
$step zen_db_prepare_input($_POST['step']);
$add_product_categories_id zen_db_prepare_input($_POST['add_product_categories_id']);
$add_product_products_id zen_db_prepare_input($_POST['add_product_products_id']);
$add_product_quantity zen_db_prepare_input($_POST['add_product_quantity']);


if (
zen_not_null($action)) {
switch (
$action) {

case 
'update':
    if (
$exist == 'yes')
    {
    
//record exist!

    
$db->Execute("UPDATE delivery_products
    
                  SET prod_quantity = '"
.$add_product_quantity."'

              WHERE del_id = '"
.$dID."' and prod_id = '".$add_product_products_id."' ");

    echo 
"UPDATE delivery_products SET prod_quantity = '".$add_product_quantity."' WHERE del_id = '".$dID."' and prod_id = '".$add_product_products_id."' ";

    
$messageStack->add('DB updated! Unique price &pound;'.$add_product_new_price.' of product ID #'.$pID.' modified for customer ID #'.$cID.' successfuly.''success');

        } else {

    
//record doesn't exist!

    
$db->Execute("INSERT INTO delivery_products (del_id, prod_id, prod_quantity)

                  VALUES ('"
.$dID."','".$add_product_products_id."','".$add_product_quantity."')");

        echo 
"INSERT INTO delivery_products (del_id, prod_id, prod_quantity) VALUES ('".$dID."','".$add_product_products_id."','".$add_product_quantity."')";

    
$messageStack->add('DB updated! Unique price &pound;'.$add_product_new_price.' for product ID #'.$pID.' added to customer ID #'.$cID.' successfuly.''success');
        }

   
ob_start();
   echo 
"Test";
   
header("Location:" zen_href_link(FILENAME_DELIVERY"dID=" $dID"NONSSL"));
   
ob_flush();

break;

...
...
...



i tried to change the form_action to other file i created (test.php)
the value sent by _POST method is valid and correct

if there is require('includes/application_top.php'); on top of the script, every time i click submit it would always go back to admin home and not process the rest of the code,

if i remove the require('includes/application_top.php'); i cannot use the function like $db->Execute, etc, which is required for the rest of the code

is there any mistake?
hope someone can help me out

many thanks