Page 1 of 1

Help Understanding Code Not Working

Posted: Sun Dec 18, 2011 12:34 pm
by gaspower
Hello,

Below is code that is not allowing some data to show on screen, and also not inserting data to database. But first I would like to correct the data not showing to screen and possibly that will solve my other issue. What thing I do not understand, is the below code works fine on a server running on (Linux 2.6.18-374.3.1.el5.lve0.8.44), (MySQL 5.0.92-community), and (PHP Version: 5.2.17 (Zend: 2.2.0)).

Code does not work correctly on (Linux 2.6.18-274.3.1.el5.centos.plus), (MySQL 5.0.77), (PHP Version: 5.1.6 (Zend: 2.1.0)), Just curious why it does not work here? Would like to know for my knowledge.

Code: Select all

<?php

if (isset($_POST['Update']))
{

    $sppc_query_raw = "select * from " . TABLE_CUSTOMERS_GROUPS . " order by customers_group_id";
    $sppc_query = tep_db_query($sppc_query_raw);
    while( $sppc = tep_db_fetch_array( $sppc_query ) ) {


     if ($sppc["customers_group_name"] != "Retail"){
//$sppc['customers_group_id']

    $c = "CG_".$sppc['customers_group_id'];

    $tmp = $_POST[$c];

    if ($tmp != 0)
    {

    $p = (100-$_POST[$c])/100;

    tep_db_query("delete from products_groups where customers_group_id = ".$sppc['customers_group_id']);




    tep_db_query ("insert into products_groups select '". $sppc['customers_group_id'] ."' as customers_group_id, ( " . $p . " * p.products_price) as customers_group_price, p.products_id from products p");



    }  //if not 0
    }  //if not Retail

    }



}


?>

<!-- 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">

    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo "Special Pricing Discount Setup"; ?></td>
            <td class="specialPrice" align="right">&nbsp;</td>
          </tr>
        </table></td>
      </tr>




      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="2" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent" align="left">
                <?php

                if (isset($_POST['Update']))
                {
                    echo "<center>Updated!</center>";
                }

                ?>
                &nbsp;</td>

              </tr>
<?php


    $sppc_query_raw = "select * from " . TABLE_CUSTOMERS_GROUPS . " order by customers_group_id";
    $sppc_query = tep_db_query($sppc_query_raw);

    while( $sppc = tep_db_fetch_array( $sppc_query ) ) {

?>

              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">
                 <td class="dataTableContent" align="left">

                  <?php

                  if ($sppc["customers_group_name"] != "Retail"){

                      echo $sppc["customers_group_name"];

                  }

                  if (isset($_POST['Update']))
                  {

                        if ($sppc["customers_group_name"] != "Retail"){

                        $c = "CG_".$sppc['customers_group_id'];

                        $tmp = $_POST[$c];

                        echo " Current Discount is $tmp%" ;


                        }
                  }
                  ?>


                  </td>

              </tr>

<?php
     }
?>
        </table></td>
      </tr>

      <tr>
       <td valign="top">
       <form action="" method="post">
        <table border="0" width="40%" cellspacing="0" cellpadding="2">

              <tr>
                <td class="smallText" align="left">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
<?php

    $sppc_query_raw = "select * from " . TABLE_CUSTOMERS_GROUPS . " order by customers_group_id";
    $sppc_query = tep_db_query($sppc_query_raw);
    while( $sppc = tep_db_fetch_array( $sppc_query ) ) {



    if ($sppc["customers_group_name"] != "Retail"){

?>

              <tr>
                <td class="smallText" align="left">Set New Percentage (%) Discount for <?=$sppc["customers_group_name"]?> :</td>
                <td><input name="CG_<?=$sppc['customers_group_id']?>" type="text" size="5" value="0"></td>
              </tr>

<?php
              }

     }
?>

              <tr>
                <td colspan="2" align="center"><input type="submit" name="Update" value="Update"></td>
              </tr>



        </table>
        </form>
       </td>
      </tr>

    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->
Image


Image

Thank you JR

Re: Help Understanding Code Not Working

Posted: Tue Dec 20, 2011 1:00 pm
by Amanda1998
Where is the value or action on your from ?

Code: Select all

<form action="" method="post">
This may fix it

Code: Select all

/** since is executing itself (on same script) **/ 
<form id='id_here' method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

Re: Help Understanding Code Not Working

Posted: Wed Dec 21, 2011 2:20 pm
by gaspower
Hello Amanda,

Thank you for the response. I did try your suggestion, but still no insertion to the database.

Thanks JR

Re: Help Understanding Code Not Working

Posted: Wed Dec 21, 2011 3:14 pm
by mikosiko
But first I would like to correct the data not showing to screen
for that you must fix this lines (around line 150 in the posted code):

Code: Select all

              <tr>
                <td class="smallText" align="left">Set New Percentage (%) Discount for <?=$sppc["customers_group_name"]?> :</td>
                <td><input name="CG_<?=$sppc['customers_group_id']?>" type="text" size="5" value="0"></td>
              </tr>
those lines are failing because you are using the short form (<? ?>) of PHP's tags , and those most likely are disabled in your new server as they probably should... the lines should be written in this way

Code: Select all

 
<tr>
   <td class="smallText" align="left">Set New Percentage (%) Discount for <php? echo $sppc["customers_group_name"];?> :</td>
   <td><input name="CG_<php? echo $sppc['customers_group_id'];?>" type="text" size="5" value="0"></td>
</tr>

regarding to your insert, echo your raw query first and check if it is valid or not

Re: Help Understanding Code Not Working

Posted: Wed Dec 21, 2011 4:54 pm
by gaspower
Hello Mikosiko

Thank you for the advice. It honestly seems like it should work, but for some reason it is not showing on the screen.

Thank you for your time.

JR

Re: Help Understanding Code Not Working

Posted: Wed Dec 21, 2011 5:28 pm
by mikosiko
then in addition to what I said previously you have some problems probably with your data or maybe with your CSS... I noticed that you second screen shows a yellow background for those fields... have you tried to take that background out?

Re: Help Understanding Code Not Working

Posted: Wed Dec 21, 2011 5:38 pm
by gaspower
Hello,

Sorry, I added the yellow to the image just so someone could tell where the issue was happening.

JR

Re: Help Understanding Code Not Working

Posted: Wed Dec 21, 2011 8:45 pm
by mikosiko
well... if is not your CSS, plus the fact that your WHILE loop is effectively executing at least twice (2 lines with "Set New Percentage.." echoed) and coincident with the 2 groups previously printed (Dealer and Tester) seems to suggest that the next possibility is just your DATA ... I don't see any other factor that could cause what you are getting