Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2009
    Posts
    206
    Plugin Contributions
    2

    Default One Field from Product Info Not Posting to Database

    I created a new field in collect_info.php that calls a bunch of checkboxes based on a new table in my database. (Also created a new column for the information in the PRODUCT table.)

    The checkboxes and labels are visible when both adding and editing a product. When I choose a checkbox and proceed to preview the product, I can see the checkbox option chosen on the previous page in the hidden fields.

    My problem is that when I submit the form, it adds everything except my new field into the database. If anyone would be so kind, I need help in understanding why I can see the hidden field in the form, but it doesn't get added to the database.

    Thank you in advance.

    In case it will help, here is the code from collect_info.php
    PHP Code:
    <?php 
    $tmp_checkbox 
    '';
    while (!
    $metaphysical->EOF) {
      
    $metaphysical_array[] = array('id' => $metaphysical->fields['metaphysical_id'],
                                    
    'text' => $metaphysical->fields['metaphysical_material']);
    $tmp_checkbox .= zen_draw_checkbox_field('metaphysical_id',$metaphysical->fields['metaphysical_id']) . $metaphysical->fields['metaphysical_material'] . "<br/>"
    $metaphysical->MoveNext();
    }
    $options_name[] = $metaphysical->fields['metaphysical_material'];
    $options_menu[] = $tmp_checkbox "\n";
    ?>

    <tr><td valign="top" class="main"><?php echo TEXT_PRODUCTS_METAPHYSICAL?></td>
    <td class="main">
        <?php for($i=0;$i<sizeof($options_name);$i++) {
                      echo 
    $options_menu[$i]; } ?>
    </td></tr>
    And from update_product.php
    PHP Code:
    <?php if (!empty($_POST['metaphysical_id'][$i])) {
            
    $metaphysical_id $_POST['metaphysical_id'];
            
    $metaphysical_id_array '';
                foreach (
    $metaphysical_id as $value) {
                    
    $metaphysical_id_array .= $value ',';
                }
        }
    ?>
    and under "manufacturer_id" in update_info.php
    PHP Code:
    <?php
    'metaphysical_id' => zen_db_prepare_input($metaphysical_id_array),
    ?>

  2. #2
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: One Field from Product Info Not Posting to Database

    Quote Originally Posted by kamelion0927 View Post
    My problem is that when I submit the form, it adds everything except my new field into the database. If anyone would be so kind, I need help in understanding why I can see the hidden field in the form, but it doesn't get added to the database.
    Exactly where among your code snippets is the code that actually inserts the data into the database? I'm not seeing it.

    Cheers
    Rod

  3. #3
    Join Date
    Dec 2009
    Posts
    206
    Plugin Contributions
    2

    Default Re: One Field from Product Info Not Posting to Database

    Thanks for your help Rod.

    That would be the last line of code I posted. The rest of the code looks like this
    PHP Code:
     if (!defined('IS_ADMIN_FLAG')) {
        die(
    'Illegal Access');
      }
      if (isset(
    $_GET['pID'])) $products_id zen_db_prepare_input($_GET['pID']);
      if (isset(
    $_POST['edit_x']) || isset($_POST['edit_y'])) {
        
    $action 'new_product';
      } elseif (
    $_POST['products_model'] . $_POST['products_url'] . $_POST['products_name'] . $_POST['products_description'] != '') {
        
    $products_date_available zen_db_prepare_input($_POST['products_date_available']);
        
    $products_date_available = (date('Y-m-d') < $products_date_available) ? $products_date_available 'null';

        
    // Data-cleaning to prevent MySQL5 data-type mismatch errors:
        
    $tmp_value zen_db_prepare_input($_POST['products_quantity']);
        
    $products_quantity = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? $tmp_value;
        
    $tmp_value zen_db_prepare_input($_POST['products_price']);
        
    $products_price = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? $tmp_value;
        
    $tmp_value zen_db_prepare_input($_POST['products_weight']);
        
    $products_weight = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? $tmp_value;
        
    $tmp_value zen_db_prepare_input($_POST['manufacturers_id']);
        
    $manufacturers_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? $tmp_value;
        
    $tmp_value zen_db_prepare_input($_POST['products_shipping_type']);
        
    $products_shipping_type = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? $tmp_value;
        
    $tmp_value zen_db_prepare_input($_POST['products_warning']);
        
    $products_warning = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? $tmp_value;
        
    $tmp_value zen_db_prepare_input($_POST['products_extra_info']);
        
    $products_extra_info = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? $tmp_value;
        
                if (!empty(
    $_POST['metaphysical_id'][$i])) {
            
    $metaphysical_id $_POST['metaphysical_id'];
            
    $metaphysical_id_array '';
                foreach (
    $metaphysical_id as $value) {
                    
    $metaphysical_id_array .= $value ',';
                }
        }
        
    $sql_data_array = array('products_quantity' => $products_quantity,
                                
    'products_type' => zen_db_prepare_input($_GET['product_type']),
                                
    'products_model' => zen_db_prepare_input($_POST['products_model']),
                                
    'products_price' => $products_price,
                                
    'products_date_available' => $products_date_available,
                                
    'products_weight' => $products_weight,
                                
    'products_status' => zen_db_prepare_input((int)$_POST['products_status']),
                                
    'products_virtual' => zen_db_prepare_input((int)$_POST['products_virtual']),
                                
    'products_tax_class_id' => zen_db_prepare_input((int)$_POST['products_tax_class_id']),
                                
    'manufacturers_id' => $manufacturers_id,
                            
    'metaphysical_id' => zen_db_prepare_input($metaphysical_id_array),
                    
    'products_shipping_type' => $products_shipping_type,
                    
    'products_warning' => $products_warning,
                    
    'products_extra_info' => $products_extra_info,
                                
    'products_quantity_order_min' => zen_db_prepare_input($_POST['products_quantity_order_min']),
                                
    'products_quantity_order_units' => zen_db_prepare_input($_POST['products_quantity_order_units']),
                                
    'products_priced_by_attribute' => zen_db_prepare_input($_POST['products_priced_by_attribute']),
                                
    'product_is_free' => zen_db_prepare_input((int)$_POST['product_is_free']),
                                
    'product_is_call' => zen_db_prepare_input((int)$_POST['product_is_call']),
                                
    'products_quantity_mixed' => zen_db_prepare_input($_POST['products_quantity_mixed']),
                                
    'product_is_always_free_shipping' => zen_db_prepare_input((int)$_POST['product_is_always_free_shipping']),
                                
    'products_qty_box_status' => zen_db_prepare_input($_POST['products_qty_box_status']),
                                
    'products_quantity_order_max' => zen_db_prepare_input($_POST['products_quantity_order_max']),
                                
    'products_sort_order' => (int)zen_db_prepare_input($_POST['products_sort_order']),
                                
    'products_discount_type' => zen_db_prepare_input($_POST['products_discount_type']),
                                
    'products_discount_type_from' => zen_db_prepare_input($_POST['products_discount_type_from']),
                                
    'products_price_sorter' => zen_db_prepare_input($_POST['products_price_sorter'])
                                );

        
    // when set to none remove from database
        // is out dated for browsers use radio only
          
    $sql_data_array['products_image'] = zen_db_prepare_input($_POST['products_image']);
          
    $new_image'true';

        if (
    $_POST['image_delete'] == 1) {
          
    $sql_data_array['products_image'] = '';
          
    $new_image'false';
        }

        if (
    $_POST['image_delete'] == 1) {
          
    $sql_data_array['products_image'] = '';
          
    $new_image'false';
        }

        if (
    $action == 'insert_product') {
          
    $insert_sql_data = array( 'products_date_added' => 'now()',
                                    
    'master_categories_id' => (int)$current_category_id);

          
    $sql_data_array array_merge($sql_data_array$insert_sql_data);

          
    zen_db_perform(TABLE_PRODUCTS$sql_data_array);
          
    $products_id zen_db_insert_id();

          
    // reset products_price_sorter for searches etc.
          
    zen_update_products_price_sorter($products_id);
          
    $db->Execute("insert into " TABLE_PRODUCTS_TO_CATEGORIES "
                        (products_id, categories_id)
                        values ('" 
    . (int)$products_id "', '" . (int)$current_category_id "')");
        } elseif (
    $action == 'update_product') {
          
    $update_sql_data = array( 'products_last_modified' => 'now()',
                                    
    'master_categories_id' => ($_POST['master_category'] > zen_db_prepare_input($_POST['master_category']) : zen_db_prepare_input($_POST['master_categories_id'])));
          
    $sql_data_array array_merge($sql_data_array$update_sql_data);
          
    zen_db_perform(TABLE_PRODUCTS$sql_data_array'update'"products_id = '" . (int)$products_id "'");
          
    // reset products_price_sorter for searches etc.
          
    zen_update_products_price_sorter((int)$products_id);
          

        
    $languages zen_get_languages();
        for (
    $i=0$n=sizeof($languages); $i<$n$i++) {
          
    $language_id $languages[$i]['id'];
          
    $sql_data_array = array('products_name' => zen_db_prepare_input($_POST['products_name'][$language_id]),
                                  
    'products_tag' => zen_db_prepare_input($_POST['products_tag'][$language_id]),
                                  
    'products_consistency' => zen_db_prepare_input($_POST['products_consistency'][$language_id]),
                                  
    'products_sizes' => zen_db_prepare_input($_POST['products_sizes'][$language_id]),
                                  
    'products_instructions' => zen_db_prepare_input($_POST['products_instructions'][$language_id]),
                                  
    'products_product_type' => zen_db_prepare_input($_POST['products_product_type'][$language_id]),
                                  
    'products_category_type' => zen_db_prepare_input($_POST['products_category_type'][$language_id]),
                                  
    'products_color' => zen_db_prepare_input($_POST['products_color'][$language_id]),
                                  
    'products_description' => zen_db_prepare_input($_POST['products_description'][$language_id]),
                                  
    'products_description2' => zen_db_prepare_input($_POST['products_description2'][$language_id]),
                                  
    'products_description3' => zen_db_prepare_input($_POST['products_description3'][$language_id]),
                                  
    'products_url' => zen_db_prepare_input($_POST['products_url'][$language_id]));
          if (
    $action == 'insert_product') {
            
    $insert_sql_data = array('products_id' => (int)$products_id,
                                     
    'language_id' => (int)$language_id);
            
    $sql_data_array array_merge($sql_data_array$insert_sql_data);
            
    zen_db_perform(TABLE_PRODUCTS_DESCRIPTION$sql_data_array);
          } elseif (
    $action == 'update_product') {
            
    zen_db_perform(TABLE_PRODUCTS_DESCRIPTION$sql_data_array'update'"products_id = '" . (int)$products_id "' and language_id = '" . (int)$language_id "'");
          }
        }

        
    // add meta tags
        
    $languages zen_get_languages();
        for (
    $i=0$n=sizeof($languages); $i<$n$i++) {
          
    $language_id $languages[$i]['id'];

          
    $sql_data_array = array('metatags_title' => zen_db_prepare_input($_POST['metatags_title'][$language_id]),
                                  
    'metatags_keywords' => zen_db_prepare_input($_POST['metatags_keywords'][$language_id]),
                                  
    'metatags_description' => zen_db_prepare_input($_POST['metatags_description'][$language_id]));
          if (
    $action == 'insert_product_meta_tags') {
            
    $insert_sql_data = array('products_id' => (int)$products_id,
                                     
    'language_id' => (int)$language_id);
            
    $sql_data_array array_merge($sql_data_array$insert_sql_data);
            
    zen_db_perform(TABLE_META_TAGS_PRODUCTS_DESCRIPTION$sql_data_array);
          } elseif (
    $action == 'update_product_meta_tags') {
            
    zen_db_perform(TABLE_META_TAGS_PRODUCTS_DESCRIPTION$sql_data_array'update'"products_id = '" . (int)$products_id "' and language_id = '" . (int)$language_id "'");
          }
        }
        
        
    // BEGIN CEON URI MAPPING 1 of 1
        
    require_once(DIR_WS_CLASSES 'class.CeonURIMappingAdminProductPages.php');
        
    $ceon_uri_mapping_admin = new CeonURIMappingAdminProductPages();
        
    $ceon_uri_mapping_admin->updateProductHandler($products_id$zc_products->get_handler($product_type));
        
    // END CEON URI MAPPING 1 of 1


        
    zen_redirect(zen_href_link(FILENAME_CATEGORIES'cPath=' $cPath '&pID=' $products_id . (isset($_GET['page']) ? '&page=' $_GET['page'] : '') . (isset($_POST['search']) ? '&search=' $_POST['search'] : '') ));
      } else {
        
    $messageStack->add_session(ERROR_NO_DATA_TO_SAVE'error');
        
    zen_redirect(zen_href_link(FILENAME_CATEGORIES'cPath=' $cPath '&pID=' $products_id . (isset($_GET['page']) ? '&page=' $_GET['page'] : '') . (isset($_POST['search']) ? '&search=' $_POST['search'] : '') ));
      }
      } 

  4. #4
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: One Field from Product Info Not Posting to Database

    Quote Originally Posted by kamelion0927 View Post
    The rest of the code looks like this
    <snip>
    if (!empty($_POST['metaphysical_id'][$i])) {
    I note the that "$i" variable isn't being set anywhere. Perhaps that's the problem?

    Cheers
    Rod

  5. #5
    Join Date
    Dec 2009
    Posts
    206
    Plugin Contributions
    2

    Default Re: One Field from Product Info Not Posting to Database

    Quote Originally Posted by RodG View Post
    I note the that "$i" variable isn't being set anywhere. Perhaps that's the problem?

    Cheers
    Rod
    Ooops! That was left over from some experimenting I was doing. I finally figured out what my issue was - I wasn't assigning the checkboxes a $pInfo->'metaphysical_id'. My actual code for the checkbox array should have been:
    PHP Code:
    <?php 
    $tmp_checkbox 
    '';
    while (!
    $metaphysical->EOF) {
    $tmp_checkbox .= zen_draw_checkbox_field('metaphysical_id',$metaphysical->fields['metaphysical_id'], $pInfo->metaphysical_id) . $metaphysical->fields['metaphysical_material'] . "<br/>"
    $metaphysical->MoveNext();
    }
    $options_name[] = $metaphysical->fields['metaphysical_material'];
    $options_menu[] = $tmp_checkbox "\n";
    ?>
    which I would have known days ago if I had taken two seconds to research the function.

    Thanks again for all your help - your posts have helped me out of more than one tight spot. :)

  6. #6
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: One Field from Product Info Not Posting to Database

    Quote Originally Posted by kamelion0927 View Post
    Thanks again for all your help - your posts have helped me out of more than one tight spot. :)
    Always happy to help where I can.

    Thanks for the feedback. Always appreciated.

    Cheers
    Rod

 

 

Similar Threads

  1. v150 Discount on Invoices Not Posting to Database Correctly
    By FloridaGoFishing in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 7
    Last Post: 31 Jul 2013, 08:53 PM
  2. Transfer of one single category from one Zen database to another
    By MeltDown in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 14 Oct 2008, 07:07 PM
  3. Remove quantity add field from product info page
    By coolglobal in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 19 Feb 2008, 01:48 PM
  4. Adding custom field from specials table to product listing and product info
    By davale in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 19 Oct 2007, 06:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg