motorcity Posted May 12, 2015 Share Posted May 12, 2015 I've been up down and around in circles with this script. I know it's poor coding, but it has served its purpose. Incredibly it has worked for years and what I'm sharing here is the same code used for multiple vendors and manufacturers. The part that completely throws me is that it still works after the change from PHP 5.2.9 to PHP 5.3 for half of the vendors and doesn't work on the other half. I keep going back to the database (also updated from mysql 5.0.96 to mysql 5.5.42) a single column "vendors2_id" in the products table makes the difference of whether this code works or fails for the most part, and I've been all through the database convinced that somehow there is some sort of corruption in a table or a single product, but I believe that just isn't the case.Now I'm asking two things; Is php5.3 that much more exacting than 5.2 that something here works but only half of the time? (The ONLY difference is the number used I.E. vendors2_id = 16 works, vendors2_id = 4 does not work.)Or is it absolutely a problem in my database? <?php require('includes/application_top.php'); define('MAX_RESULTS', '1000'); //set_time_limit(300); function get_products_reorder_to($products_quantity, $reorder_quantity, $shelf_pack,$products_reorder_to){ $new_reorder_to = 0; if($products_quantity < $reorder_quantity && $shelf_pack > 0){ for($new_reorder_to = $shelf_pack;($new_reorder_to + $products_quantity) < $reorder_quantity;){ $new_reorder_to += $shelf_pack; } } if($products_reorder_to > 0) $new_reorder_to = $products_reorder_to; return $new_reorder_to; } //end function if($_POST['reset']){ $reset_query = tep_db_query("select products_id, products_quantity, shelf_pack, reorder_quantity from " . TABLE_PRODUCTS . " where vendors2_id = 16 and products_quantity < reorder_quantity"); while ($reset_select = tep_db_fetch_array($reset_query)) { $jd = get_products_reorder_to($reset_select['products_quantity'], $reset_select['reorder_quantity'], $reset_select['shelf_pack'], 0); mysql_query("UPDATE " . TABLE_PRODUCTS . " SET products_reorder_to = '" . $jd . "' WHERE vendors2_id = 16 and products_id = '" . $reset_select['products_id'] . "'"); } mysql_query("UPDATE " . TABLE_PRODUCTS . " SET approved = '1' WHERE vendors2_id = 16 and products_quantity < reorder_quantity "); mysql_query("UPDATE " . TABLE_PRODUCTS . " SET approved = '0', products_reorder_to = '0' WHERE vendors2_id = 16 and products_quantity >= reorder_quantity "); }//post reset if($_POST['save'] || $_POST['autosave'] == '1'){ if($_POST['add2order'] != '') $idchecked = join(",", $_POST['add2order']); if($_POST['add2orderlist'] != '') $idlist = join(",", $_POST['add2orderlist']); mysql_query("UPDATE " . TABLE_PRODUCTS . " SET approved = 1 WHERE vendors2_id = 16 and products_id in (" . $idchecked . ")"); mysql_query("UPDATE " . TABLE_PRODUCTS . " SET approved = 0 WHERE vendors2_id = 16 and products_id in (" . $idlist . ") and products_id NOT in (" . $idchecked . ")"); }//post save ?> <!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"> <script language="javascript" src="includes/general.js"></script> </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 //--> <form name="order_quantity" method="post"> <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'); $sorted = $HTTP_GET_VARS['sorted']; $orderby = $HTTP_GET_VARS['orderby']; if ($sorted !== "ASC" and $sorted !== "DESC") $sorted = "ASC"; ?> <!-- 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> <td class="pageHeading"><?php echo HEADING_TITLE; ?></td> <?php $products_query_raw = "select p.products_id, p.products_model, p.products_quantity, pd.products_name, p.products_sku, p.reorder_quantity, p.products_reorder_to, p.shelf_pack, p.vendors_product_price, pr.manufacturers_name, p2c.categories_id from " . TABLE_PRODUCTS . " p inner join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id inner join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c on p.products_id = p2c.products_id left outer join " . TABLE_MANUFACTURERS . " pr on p.manufacturers_id = pr.manufacturers_id where p.vendors2_id = 16 and pd.language_id = '" . $languages_id. "' and p.approved=1 group by pd.products_id "; $products_query = tep_db_query($products_query_raw); while ($products = tep_db_fetch_array($products_query)) { $new_reorder_to = get_products_reorder_to($products['products_quantity'], $products['reorder_quantity'], $products['shelf_pack'], $products['products_reorder_to']); $subtotal = $new_reorder_to * $products['vendors_product_price']; $total += $subtotal; } ?> <td class="pageHeading" align="left">ABC Company</td> <td class="main" align="left">Grand Total = $<?php echo $total;?></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> <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 TABLE_HEADING_NUMBER; ?></td> <td class="dataTableHeadingContent"><?php if (!isset($orderby) or ($orderby == "sku" and $sorted == "ASC")) $to_sort = "DESC"; else $to_sort = "ASC"; echo '<a href="' . tep_href_link(FILENAME_STATS_INVENTORY16, 'orderby=sku&sorted='. $to_sort.($_GET['page']>0?'&page='.$_GET['page']:'')) . '" class="headerLink">' .TABLE_HEADING_PROD_ID . '</a>'; ?> </td> <td class="dataTableHeadingContent"><?php if (!isset($orderby) or ($orderby == "model" and $sorted == "ASC")) $to_sort = "DESC"; else $to_sort = "ASC"; echo '<a href="' . tep_href_link(FILENAME_STATS_INVENTORY16, 'orderby=model&sorted='. $to_sort.($_GET['page']>0?'&page='.$_GET['page']:'')) . '" class="headerLink">' . TABLE_HEADING_MODEL . '</a>'; ?></td> <td class="dataTableHeadingContent"><?php if (!isset($orderby) or ($orderby == "name" and $sorted == "ASC")) $to_sort = "DESC"; else $to_sort = "ASC"; echo '<a href="' . tep_href_link(FILENAME_STATS_INVENTORY16, 'orderby=name&sorted='. $to_sort.($_GET['page']>0?'&page='.$_GET['page']:'')) . '" class="headerLink">' . TABLE_HEADING_PRODUCTS . '</a>'; ?></td> <td class="dataTableHeadingContent" align="right"><?php if (!isset($orderby) or ($orderby == "cost" and $sorted == "ASC")) $to_sort = "DESC"; else $to_sort = "ASC"; echo '<a href="' . tep_href_link(FILENAME_STATS_INVENTORY16, 'orderby=cost&sorted='. $to_sort.($_GET['page']>0?'&page='.$_GET['page']:'')) . '" class="headerLink">' .TABLE_HEADING_PRICE_LEFT . '</a>'; ?> </td> <td class="dataTableHeadingContent" align="right"><?php if (!isset($orderby) or ($orderby == "shelf" and $sorted == "ASC")) $to_sort = "DESC"; else $to_sort = "ASC"; echo '<a href="' . tep_href_link(FILENAME_STATS_INVENTORY16, 'orderby=shelf&sorted='. $to_sort.($_GET['page']>0?'&page='.$_GET['page']:'')) . '" class="headerLink">' .TABLE_HEADING_SHELF . '</a>'; ?> </td> <td class="dataTableHeadingContent" align="right" bgcolor="FFCCCC"><?php if (!isset($orderby) or ($orderby == "stock" and $sorted == "ASC")) $to_sort = "DESC"; else $to_sort = "ASC"; echo '<a href="' . tep_href_link(FILENAME_STATS_INVENTORY16, 'orderby=stock&sorted='. $to_sort.($_GET['page']>0?'&page='.$_GET['page']:'')) . '" class="headerLink">' .TABLE_HEADING_QTY_LEFT . '</a>'; ?> </td> <td class="dataTableHeadingContent" align="right" bgcolor="CCFF99"><?php if (!isset($orderby) or ($orderby == "reorder" and $sorted == "ASC")) $to_sort = "DESC"; else $to_sort = "ASC"; echo '<a href="' . tep_href_link(FILENAME_STATS_INVENTORY16, 'orderby=reorder&sorted='. $to_sort.($_GET['page']>0?'&page='.$_GET['page']:'')) . '" class="headerLink">' .TABLE_HEADING_REORDER . '</a>'; ?> </td> <td class="dataTableHeadingContent" align="right"><?php if (!isset($orderby) or ($orderby == "reorder2" and $sorted == "ASC")) $to_sort = "DESC"; else $to_sort = "ASC"; echo '<a href="' . tep_href_link(FILENAME_STATS_INVENTORY16, 'orderby=reorder2&sorted='. $to_sort.($_GET['page']>0?'&page='.$_GET['page']:'')) . '" class="headerLink">' .TABLE_HEADING_REORDER2 . '</a>'; ?> </td> <td class="dataTableHeadingContent" align="right"><?php if (!isset($orderby) or ($orderby == "total" and $sorted == "ASC")) $to_sort = "DESC"; else $to_sort = "ASC"; echo '<a href="' . tep_href_link(FILENAME_STATS_INVENTORY16, 'orderby=total&sorted='. $to_sort.($_GET['page']>0?'&page='.$_GET['page']:'')) . '" class="headerLink">'. TABLE_HEADING_LINE_T. '</a>'; ?></td> <td class="dataTableHeadingContent" align="right"><?php if (!isset($orderby) or ($orderby == "approved" and $sorted == "ASC")) $to_sort = "DESC"; else $to_sort = "ASC"; echo '<a href="' . tep_href_link(FILENAME_STATS_INVENTORY16, 'orderby=approved&sorted='. $to_sort.($_GET['page']>0?'&page='.$_GET['page']:'')) . '" class="headerLink">'.TABLE_HEADING_CHECK_T. '</a>'; ?></td> </tr> <?php if ($HTTP_GET_VARS['page'] > 1) $rows = $HTTP_GET_VARS['page'] * 20 - 20; if ($orderby == "name") {$db_orderby = "pd.products_name";} elseif ($orderby == "stock") {$db_orderby = "p.products_quantity";} elseif ($orderby == "reorder") {$db_orderby = "p.reorder_quantity";} elseif ($orderby == "reorder2") {$db_orderby = "p.products_reorder_to";} elseif ($orderby == "shelf") {$db_orderby = "p.shelf_pack";} elseif ($orderby == "cost") {$db_orderby = "p.vendors_product_price";} elseif ($orderby == "sku") {$db_orderby = "p.products_sku";} elseif ($orderby == "model") {$db_orderby = "p.products_model";} elseif ($orderby == "total") {$db_orderby = "total";} elseif ($orderby == "approved") {$db_orderby = "p.approved";$secsort=",total desc";} else {$db_orderby = "p.approved";$secsort=",total desc"; $sorted='DESC';} $products_query_raw = "select p.products_id, p.products_model, p.products_quantity, pd.products_name, p.products_sku, p.reorder_quantity, p.products_reorder_to, p.shelf_pack, p.vendors_product_price, pr.manufacturers_name,(p.vendors_product_price * p.products_reorder_to) as total, p.approved, p2c.categories_id from " . TABLE_PRODUCTS . " p inner join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id inner join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c on p.products_id = p2c.products_id left outer join " . TABLE_MANUFACTURERS . " pr on p.manufacturers_id = pr.manufacturers_id where p.vendors2_id = 16 and pd.language_id = '" . $languages_id. "' group by pd.products_id order by $db_orderby $sorted $secsort"; $products_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_RESULTS, $products_query_raw, $products_query_numrows); $products_query = tep_db_query($products_query_raw); while ($products = tep_db_fetch_array($products_query)) { $rows++; if (strlen($rows) < 2) { $rows = '0' . $rows; } $products_id = $products['products_id']; $new_reorder_to = get_products_reorder_to($products['products_quantity'], $products['reorder_quantity'], $products['shelf_pack'], $products['products_reorder_to']); $subtotal = $new_reorder_to * $products['vendors_product_price']; $products_approved = tep_db_query("select approved from " . TABLE_PRODUCTS . " where products_id = $products_id"); $product_approved = tep_db_fetch_array($products_approved); $p_approved = $product_approved["approved"]; if($p_approved==1) $pagetotal += $subtotal; $approvedbutton = tep_draw_checkbox_field('add2order[]',$products_id,(($p_approved==1)? 'true':'')) . ' ' . (tep_not_null(ENTRY_NEWSLETTER_TEXT) ? '<span class="inputRequirement">' . 'Approved'. '</span>': ''); echo '<input type="hidden" name="add2orderlist[]" value="'.$products_id.'">'; ?> <tr class="dataTableRow"onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)"> <td align="left" class="dataTableContent"><?php echo $rows; ?>.</td> <td align="right" class="dataTableContent"><?php echo $products['products_sku']; ?></td> <td align="left" class="dataTableContent"><?php echo $products['products_model']; ?></td> <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $products['categories_id'] . '&pID='.$products['products_id'].'&action=new_product') . '" TARGET="_blank"><b>' . $products['products_name'] . '</a></b>'; ?></td> <td align="right" class="dataTableContent"><?php echo $products['vendors_product_price']; ?></td> <td align="right" class="dataTableContent"><?php echo $products['shelf_pack']; ?></td> <td align="right" bgcolor="FFCCCC" class="dataTableContent"><?php echo $products['products_quantity']; ?></td> <td align="right" bgcolor="CCFF99" class="dataTableContent"><?php echo $products['reorder_quantity']; ?></td> <td align="right" width="50" class="dataTableContent"><?php echo tep_draw_input_field('reorder2['.$products_id.']', $new_reorder_to, 'style="width: 100%"'); ?></td> <td align="right" class="dataTableContent"><?php echo sprintf("%01.2f",$subtotal); ?></td> <td align="right" class="dataTableContent"><?php echo $approvedbutton; ?></td> </tr> <?php //} unset($cPath_array); unset($p_category_array); } ?> <tr class="dataTableHeadingRow"> <td class="dataTableHeadingContent" colspan="4" align="center"><input type="submit" name="reset" value="Send/Reset Order" onClick="return confirm('Send/Reset all orders?');"></td> <td class="dataTableHeadingContent" colspan="5" align="center"><input type="submit" name="save" value="Save Order" onClick="return confirm('Save orders?');"></td> <td class="dataTableHeadingContent" colspan="2"><?php echo 'Sub Total : $'.$pagetotal; ?></td> </tr> </table></td> </tr> </form> <tr> <td colspan="3"><table border="0" width="90%" cellspacing="0" cellpadding="2"> <tr> <td class="smallText" valign="top"><?php echo $products_split->display_count($products_query_numrows, MAX_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td> <td class="smallText" align="right"><?php echo $products_split->display_links($products_query_numrows, MAX_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page'], "orderby=" . $orderby . "&sorted=" . $sorted); ?> </td> </tr> </table></td> </tr> </table></td> </tr> </table></td> <!-- body_text_eof //--> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/296238-updating-to-php-53-poorr-code-or-data/ Share on other sites More sharing options...
motorcity Posted May 12, 2015 Author Share Posted May 12, 2015 I should probably explain works or doesn't work. Either way the file displays a sortable list by column headings with suggested products to order based on quantity in stock. The user can override the "approved" by clicking the checkbox off. What doesn't work is RESET or SAVE the order. Thanks for looking and any suggestions you may have. Quote Link to comment https://forums.phpfreaks.com/topic/296238-updating-to-php-53-poorr-code-or-data/#findComment-1511546 Share on other sites More sharing options...
mac_gyver Posted May 12, 2015 Share Posted May 12, 2015 (edited) What doesn't work is RESET or SAVE the order. that may be WHAT doesn't work, but exactly what about it doesn't work. are the values not displayed for picking, does the page just 'refresh' without apparently doing anything when the form is submitted, is the form data not present in the form processing code after the form was submitted, are there php errors, query errors, is the data just not updated in the database table, or is the data actually present in the database table but it is not having an affect when it's being used? in short, what symptom do you see in front of you, since we're are sitting there with you to see it, that leads you to believe 'it doesn't work'? there's very little backwardly incompatible differences between most of the php versions, and these things are generally obscure things that most code doesn't use (they are documented in the php.net documentation, appendix.) most problems like this are due to php configuration differences. in fact, only in the php5.4 version were a number of obsolete things finally removed (your use of $HTTP_GET_VARS for example aren't present as of php5.4+). edit: you also mentioned that the problem is associated with - vendors2_id = 16 works, vendors2_id = 4 does not work. the posted code only has vendors2_id hard coded as a 16. is the posted code the actual code that doesn't work and if not, why do you have different code that only differs in a value that's has hard coded that value rather than using one instance of the code and using a variable for the, well, variable value in it? if the code with a vendors2_id = 4 in it doesn't work, perhaps that's the code you need to post. Edited May 12, 2015 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/296238-updating-to-php-53-poorr-code-or-data/#findComment-1511547 Share on other sites More sharing options...
motorcity Posted May 12, 2015 Author Share Posted May 12, 2015 (edited) Thanks. To be more precise on form submission $_POST['reset'] or $_POST['save'] if the script is working you get a page refresh and a new total reflecting any changes, and a revised sort order. If not working, it still refreshes the page but it changes nothing. There are a number of php notices for undefined variables and indexes, but those were there before php5.3 and are common between those versions that work and those that don't. That the posted code is exactly the same with the hard coded vendors2_id being the only difference is really the point. And it sounds like your judgement is the problem isn't in the code. With a possible check of the php configuration probably due. Edited May 12, 2015 by motorcity Quote Link to comment https://forums.phpfreaks.com/topic/296238-updating-to-php-53-poorr-code-or-data/#findComment-1511555 Share on other sites More sharing options...
mac_gyver Posted May 12, 2015 Share Posted May 12, 2015 in the non-working case, you need to actually pin down what the code and data is doing, before you can even locate what needs to be fixed. you could for example have some broken html on the page for the id = 4 case that's causing the form to be invalid markup and it does not submit any data. the data itself may be invalid (or empty) and is resulting in query errors or a query that's not matching anything. your code could even be running twice for some reason and updating the data correctly, but is also updating it again back to the original values. you need to determine exactly what code is running, what values are being used by the code, and what is being returned from statements. 1. make sure that the code where the update queries are at is actually running. you should be forming the sql statements in a php variable (always), then just use that variable as input to the function that's running the query. you can then echo/log the contents of that variable for debugging purposes so that you will know that the queries are being ran and what data they actually contain. 2. make sure that all the queries are running without any errors. you should (always) test the returned value from a query for errors. an UPDATE query will return a false value when there is a query error. you can echo/log the mysql_error() information to let you know what the error is. and as a side note: you are using both the tep_db_query() and mysql_query() statements to perform queries. you could have a case where there are multiple database connections (even a default one set up by the php installation) and each of those methods of running a query could be operating on different databases. perhaps the database connections for one id = value are all using the same database and the code works, whereas for the other id = value, there are errors or missing data due to multiple database connections being used in the code. Quote Link to comment https://forums.phpfreaks.com/topic/296238-updating-to-php-53-poorr-code-or-data/#findComment-1511559 Share on other sites More sharing options...
motorcity Posted May 12, 2015 Author Share Posted May 12, 2015 Really appreciate you taking a look here. I thought that last part about tep_db_ or mysql_ query was worth a quick going over and found that using $query = tep_db_query() in the place of mysql_query didn't bother any functioning files, and it didn't change anything that doesn't work. There has to be some sort of corruption in the data that just blows my mind because it spans multiple product groups and never reared its head until this switch in php & mysql. Quote Link to comment https://forums.phpfreaks.com/topic/296238-updating-to-php-53-poorr-code-or-data/#findComment-1511628 Share on other sites More sharing options...
mac_gyver Posted May 13, 2015 Share Posted May 13, 2015 my supposition about different databases/connections was just one of the many possible things that could be causing the problem. i/we could probably list a dozen different possible things, but won't, because your setup could be doing something different than what i/we have in mind, and the actual problem could be the 13th item that no one thought of. you need to 'close the loop' by providing some investigation and feedback in order to narrow down the possibilities. solving this will require that you actually add the things that i mentioned to the code in order to pin down where and what is actually happening. Quote Link to comment https://forums.phpfreaks.com/topic/296238-updating-to-php-53-poorr-code-or-data/#findComment-1511643 Share on other sites More sharing options...
motorcity Posted May 25, 2015 Author Share Posted May 25, 2015 (edited) Finally figured this out by comparing the 5.2.9 php.ini to the current php 5.3.29 php.ini The default max_input_vars = 1000 was the culprit. Thanks for all the help, I really do appreciate it. ~Motorcity Not sure how to mark this solved, but it is. Edited May 25, 2015 by motorcity Quote Link to comment https://forums.phpfreaks.com/topic/296238-updating-to-php-53-poorr-code-or-data/#findComment-1512588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.