staaf Posted October 2, 2009 Posted October 2, 2009 Im using Oscommerce v2.2 rc2a. Hopefully someone can help me out on this. I have added a field to the database table "products_description" VARCHAR(1) called "products_gender". I will show u the pieces of code with the added field in it: admin/categories.php $sql_data_array = array('products_name' => tep_db_prepare_input($HTTP_POST_VARS['products_name'][$language_id]), 'products_description' => tep_db_prepare_input($HTTP_POST_VARS['products_description'][$language_id]), 'products_url' => tep_db_prepare_input($HTTP_POST_VARS['products_url'][$language_id]), 'products_gender' => tep_db_prepare_input($HTTP_POST_VARS['products_gender'][$language_id])); $description_query = tep_db_query("select language_id, products_name, products_description, products_url, products_gender from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$products_id . "'"); while ($description = tep_db_fetch_array($description_query)) { tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url, products_gender, products_viewed) values ('" . (int)$dup_products_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['products_name']) . "', '" . tep_db_input($description['products_description']) . "', '" . tep_db_input($description['products_url']) . "', '" . tep_db_input($description['products_gender']) . "', '0')"); } if ($action == 'new_product') { $parameters = array('products_name' => '', 'products_description' => '', 'products_url' => '', 'products_gender' => '', 'products_id' => '', 'products_quantity' => '', 'products_model' => '', 'products_image' => '', 'products_price' => '', 'products_weight' => '', 'products_date_added' => '', 'products_last_modified' => '', 'products_date_available' => '', 'products_status' => '', 'products_tax_class_id' => '', 'manufacturers_id' => ''); if (isset($HTTP_GET_VARS['pID']) && empty($HTTP_POST_VARS)) { $product_query = tep_db_query("select pd.products_name, pd.products_description, pd.products_url, pd.products_gender, p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'"); $product = tep_db_fetch_array($product_query); $pInfo->objectInfo($product); } elseif (tep_not_null($HTTP_POST_VARS)) { $pInfo->objectInfo($HTTP_POST_VARS); $products_name = $HTTP_POST_VARS['products_name']; $products_description = $HTTP_POST_VARS['products_description']; $products_url = $HTTP_POST_VARS['products_url']; $products_gender = $HTTP_POST_VARS['products_gender']; } <tr> <td class="main"><?php echo TEXT_PRODUCTS_GENDER; ?> <i>(m, v of u)</i></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_gender[' . $languages[$i]['id'] . ']', (isset($products_gender[$languages[$i]['id']]) ? stripslashes($products_gender[$languages[$i]['id']]) : tep_get_products_gender($pInfo->products_id, $languages[$i]['id']))); ?></td> </tr> <tr> admin/includes/functions/general.php function tep_get_products_gender($product_id, $language_id) { $product_query = tep_db_query("select products_gender from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language_id . "'"); $product = tep_db_fetch_array($product_query); return $product['products_gender']; } The problem is when I submit a new product, or edit an existing product the value that I filled in my custom added field "products_gender" stays empty in the database without getting any kind of error. Can someone please help me with this.
burt Posted October 2, 2009 Posted October 2, 2009 In catgegories.php you have to utilise the hidden fields as far as I recall. have a search in there for "hidden"
staaf Posted October 2, 2009 Author Posted October 2, 2009 In catgegories.php you have to utilise the hidden fields as far as I recall. have a search in there for "hidden" Thanks but I forgot to post that piece of code, i had allready done that: /* Re-Post all POST'ed variables */ reset($HTTP_POST_VARS); while (list($key, $value) = each($HTTP_POST_VARS)) { if (!is_array($HTTP_POST_VARS[$key])) { echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value))); } } $languages = tep_get_languages(); for ($i=0, $n=sizeof($languages); $i<$n; $i++) { echo tep_draw_hidden_field('products_name[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_name[$languages[$i]['id']]))); echo tep_draw_hidden_field('products_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_description[$languages[$i]['id']]))); echo tep_draw_hidden_field('products_url[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_url[$languages[$i]['id']]))); echo tep_draw_hidden_field('products_gender[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_gender[$languages[$i]['id']]))); }
multimixer Posted October 2, 2009 Posted October 2, 2009 How are your DB settings for this field? My community profile | Template system for osCommerce - New: Responsive | Feedback channel
staaf Posted October 2, 2009 Author Posted October 2, 2009 How are your DB settings for this field? `products_gender` varchar(1) NOT NULL,
multimixer Posted October 2, 2009 Posted October 2, 2009 try with Null = yes Default = NULL My community profile | Template system for osCommerce - New: Responsive | Feedback channel
staaf Posted October 2, 2009 Author Posted October 2, 2009 try with Null = yes Default = NULL changed it like you said but unfortunatly I still have the problem.
multimixer Posted October 2, 2009 Posted October 2, 2009 I had the same problem a couple of months ago, putting the product name in plural into the DB, and I solved it somehow, I need to remember how :) My community profile | Template system for osCommerce - New: Responsive | Feedback channel
staaf Posted October 5, 2009 Author Posted October 5, 2009 I solved it, totally forgot to make a for lus @ <?php for ($i=0, $n=sizeof($languages); $i<$n; $i++) { ?> <tr> <td class="main"><?php echo TEXT_PRODUCTS_GENDER; ?> <i>(m, v of u)</i></td> <td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . ' ' . tep_draw_input_field('products_gender[' . $languages[$i]['id'] . ']', (isset($products_gender[$languages[$i]['id']]) ? stripslashes($products_gender[$languages[$i]['id']]) : tep_get_products_gender($pInfo->products_id, $languages[$i]['id']))); ?></td> </tr> <?php } ?>
Recommended Posts
Archived
This topic is now archived and is closed to further replies.