Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Quick Updates Help


partsace

Recommended Posts

I am working on the quick updates contributions. I am having problems with updating a field in by database that uses both numbers and characters. The field is products_years. We sell parts for cars online and we need this field to let customers know if the part they are about to purchase is for their vehicle. Below is the code that I am using. The problem is that when I change the products_years field, it thinks it?s a number field. For instance, if I put 1995-1998, it puts in -3 after the update is done. Or if I put "All", it keeps is the original field. Does anyone have a clue on how I can make this work or what I am doing wrong?

 

Scott

       foreach($HTTP_POST_VARS['product_new_years'] as $id => $new_years) {

        mysql_query("UPDATE products SET products_years=$new_years WHERE products_id=$id");

      }

Link to comment
Share on other sites

I forgot to let you know that the table setting is:

 

products_years VARCHAR(25) DEFAULT NULL

 

I have tried tinytext, didn't work. I have tried puting quotes around the number or word, didn't work. Below is the code for quick_updates.php.

 

<?php

/*

 $Id: quick_updates.php,v 1.4b $



 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com



 Based on the original script contributed by Burt (burt@xwww.co.uk)

       and by Henri Bredehoeft (hrb@nermica.net)

       and Blue Dog (simon@bluedogweb.co.uk)

 updated by GniDhal (fx@geniehalles.com) & xaglo (xaglo@free.fr)



 Copyright (c) 2003 osCommerce



 Released under the GNU General Public License

*/



 require('includes/application_top.php');

if ($HTTP_POST_VARS) {

  if ($action == "update") {

  $messageStack->add(TEXT_PRODUCTS_UPDATED, 'success');



      foreach($HTTP_POST_VARS['product_new_price'] as $id => $new_price) {

        mysql_query("UPDATE products SET products_price=$new_price WHERE products_id=$id");

      }

      foreach($HTTP_POST_VARS['product_new_weight'] as $id => $new_weight) {

        mysql_query("UPDATE products SET products_weight=$new_weight WHERE products_id=$id");

      }

      foreach($HTTP_POST_VARS['product_new_years'] as $id => $new_years) {

        mysql_query("UPDATE products SET products_years=$new_years WHERE products_id=$id");

      }

      foreach($HTTP_POST_VARS['product_new_quantity'] as $id => $new_quantity) {

        mysql_query("UPDATE products SET products_quantity=$new_quantity WHERE products_id=$id");

      }

      foreach($HTTP_POST_VARS['product_new_status'] as $id => $new_status) {

        tep_set_product_status($id, $new_status);

      }

      foreach($HTTP_POST_VARS['product_new_tax'] as $id => $new_tax_id) {

        mysql_query("UPDATE products SET products_tax_class_id=$new_tax_id WHERE products_id=$id");

      }

  }





}



?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html <?php echo HTML_PARAMS; ?>>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">

<title><?php echo TITLE; ?></title>

<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">

</head>

<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">

<!-- header //-->

<?php require(DIR_WS_INCLUDES . 'header.php'); ?>

<!-- header_eof //-->



<!-- body //-->

<table border="0" width="100%" cellspacing="2" cellpadding="2">

 <tr>

   <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">

<!-- left_navigation //-->

<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>

<!-- left_navigation_eof //-->

       </table></td>

<!-- body_text //-->



<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">

     <tr>

       <td><table border="0" width="100%" cellspacing="0" cellpadding="0">

         <tr>

         <form name="update" method="post" action="<?php echo "$PHP_SELF?action=update"; ?>">

           <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>

           <td align=middle><?php if ($HTTP_GET_VARS['pID']) {

       echo tep_image_submit('button_update.gif', IMAGE_UPDATE);

     } else {

       echo tep_image_submit('button_update.gif', IMAGE_INSERT);

     }

     echo '  <a href="' . tep_href_link(FILENAME_QUICK_UPDATES, 'cPath=' . $cPath . '&pID=' . $HTTP_GET_VARS['pID']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';?>

          </td>



           <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>

         </tr>

       </table></td>

     </tr>

       <td><table border="0" width="100%" cellspacing="0" cellpadding="2">

         <tr>

           <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">

             <tr class="dataTableHeadingRow">

               <td class="dataTableHeadingContent"><?php echo " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_model DESC' )."" >-</a> " . TABLE_HEADING_MODEL . " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_model ASC' )."" >+</a>"; ?> </td>

               <td class="dataTableHeadingContent"><?php echo " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=pd.products_name DESC' )."" >-</a> " . TABLE_HEADING_PRODUCTS . " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=pd.products_name ASC' )."" >+</a>"; ?> </td>

               <td class="dataTableHeadingContent" align="center"><?php echo " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_status DESC' )."" >-</a> " . TABLE_HEADING_STATUS . " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_status ASC' )."" >+</a>"; ?> <br>off / on</td>

               <td class="dataTableHeadingContent" align="center"><?php echo " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_weight DESC' ) ."" >-</a> " . TABLE_HEADING_WEIGHT . " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_weight ASC' ) ."" >+</a> "; ?> </td>

               <td class="dataTableHeadingContent" align="center"><?php echo " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_quantity DESC' )."" >-</a> " . TABLE_HEADING_QUANTITY . " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_quantity ASC' )."" >+</a> "; ?> </td>

               <td class="dataTableHeadingContent" align="center"><?php echo " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_price DESC' ) ."" >-</a>" . TABLE_HEADING_PRICE . " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_price ASC' ) ."" >+</a>"; ?> </td>

               <td class="dataTableHeadingContent" align="center"><?php echo " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_years DESC' ) ."" >-</a>" . TABLE_HEADING_YEARS . " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_years ASC' ) ."" >+</a>"; ?> </td>

               <td class="dataTableHeadingContent" align="center"><?php echo " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_tax_class_id DESC' )."" >-</a> " . TABLE_HEADING_TAX . " <a href="" . tep_href_link( FILENAME_QUICK_UPDATES, 'sort_by=p.products_tax_class_id ASC' )."" >+</a> "; ?> </td>

             </tr>

         <tr class="datatableRow">

<?



   $tax_class_array = array(array('id' => '0', 'text' => NO_TAX_TEXT));

   $tax_class_query = tep_db_query("select tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");

   while ($tax_class = tep_db_fetch_array($tax_class_query)) {

     $tax_class_array[] = array('id' => $tax_class['tax_class_id'],

                                'text' => $tax_class['tax_class_title']);

   }



($sort_by) ? $sort_by = 'ORDER BY '.$sort_by : $sort_by = $HTTP_POST_VARS['sort_order'];

 $result = tep_db_query("SELECT DISTINCT

                                p.products_id,

                                p.products_model,

                                pd.products_name,

                                p.products_years,

                                p.products_status,

                                p.products_weight,

                                p.products_quantity,

                                p.products_price,

                                p.products_tax_class_id

                          FROM  " . TABLE_PRODUCTS . " as p

                          LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " as pd  ON (p.products_id = pd.products_id)

                          WHERE pd.language_id = '$languages_id'

                          $sort_by

                          ");



   if ($row = mysql_fetch_array($result)) {

       do {

          echo tep_draw_hidden_field( 'sort_order', $sort_by);

          echo '<tr class="dataTableRow" onmouseover="this.className='dataTableRowOver';this.style.cursor='hand'" onmouseout="this.className='dataTableRow'">';

          echo "<td class="smallText" >".$row["products_model"]."</td>n";

          echo "<td><a href="".tep_href_link (FILENAME_CATEGORIES, 'pID='.$row["products_id"].'&action=new_product'). "">".$row["products_name"]."</a></td>n";

         if ($row['products_status'] == '1') {

          echo "<td class="smallText" align="center"><input  type="radio" name="product_new_status[".$row['products_id']."]" value="0" ><input type="radio" name="product_new_status[".$row['products_id']."]" value="1" checked ></td>n";

         } else {

          echo "<td nowrap   align="center"><input type="radio" style="background-color: #EEEEEE" name="product_new_status[".$row['products_id']."]" value="0" checked ><input type="radio" style="background-color: #EEEEEE" name="product_new_status[".$row['products_id']."]" value="1"></td>n";

         }

          echo "<td nowrap   align="center"><input type="text" size="6" name="product_new_weight[".$row['products_id']."]" value={$row['products_weight']}></td>n";

          echo "<td class="smallText" align="center"><input type="text" size="3" name="product_new_quantity[".$row['products_id']."]" value={$row['products_quantity']}></td>n";

          echo "<td class="smallText" align="center"><input type="text" size="7" name="product_new_price[".$row['products_id']."]" value={$row['products_price']}></td>n";

          echo "<td class="smallText" align="center"><input type="text" size="9" name="product_new_years[".$row['products_id']."]" value={$row['products_years']}></td>n";

          echo "<td class="smallText" align="center">".tep_draw_pull_down_menu("product_new_tax[".$row['products_id']."]"", $tax_class_array, $row['products_tax_class_id'])."</td>n";



      }

       while($row = mysql_fetch_array($result) );

   }



   echo "</table>n";

?></td>

         </tr>

         </table></td>

         </tr>

         <tr>

           <td colspan="3"><table border="0" width="100%" cellspacing="0" cellpadding="2">



           </table></td>

         </tr>

       </table></td>

     </tr>

   </table></td>

               <table width="100%" border="0" cellspacing="1">

<tr>

<td align=middle><?php if ($HTTP_GET_VARS['pID']) {

       echo tep_image_submit('button_update.gif', IMAGE_UPDATE);

     } else {

       echo tep_image_submit('button_update.gif', IMAGE_INSERT);

     }

     echo '  <a href="' . tep_href_link(FILENAME_QUICK_UPDATES, 'cPath=' . $cPath . '&pID=' . $HTTP_GET_VARS['pID']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';

?></td>

</tr>



</table>

</form>

<!-- body_text_eof //-->

 </tr>

</table>

<!-- body_eof //-->

 </tr>

</table>

<!-- body_eof //-->



<!-- footer //-->

<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>

<!-- footer_eof //-->

</body>

</html>

<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

 

Thanks,

 

Scott

Link to comment
Share on other sites

  • 2 weeks later...

I dont suppose it crossed your mind to make that image a little smaller and NOT a .bmp!!

 

It is nearly 2.3mb in size!!! :roll:

 

Anywway, yes that is how it should look, except you have not uploaded all the additions that are included in the mod.

 

Dont belazy now, look at all the docs in the mod, you have missed out images, language files etc.

Upload them all and it will be better.

 

CC.

Link to comment
Share on other sites

I am working on the quick updates contributions. I am having problems with updating a field in by database that uses both numbers and characters. The field is products_years. We sell parts for cars online and we need this field to let customers know if the part they are about to purchase is for their vehicle. Below is the code that I am using. The problem is that when I change the products_years field, it thinks it?s a number field. For instance, if I put 1995-1998, it puts in -3 after the update is done. Or if I put "All", it keeps is the original field. Does anyone have a clue on how I can make this work or what I am doing wrong?

 

Scott

       foreach($HTTP_POST_VARS['product_new_years'] as $id => $new_years) {

        mysql_query("UPDATE products SET products_years=$new_years WHERE products_id=$id");

      }

 

try whith another separator than - or you have to format your data in string format. if you put 12-15 the result will be 3 too !

your imput is interpreted like integer.

for best result use 2 fields : year1 and year2 and make a controle of the imputs by a date format :wink:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...