Jump to content

Bizarre variable problem


Zonkel

Recommended Posts

Hi,

 

I'm bug fixing some old code written by someone else and there is a problem where it is trying to display the information to the user, but it also sends an email to the user (using a session variable for the address). The problem is however, it is supposed to have a date calculated depending on where we are in the current year, this works correctly for what is shown to the user, but shows the wrong date in the email it sends. Code:

 

        $expdate = end_period($rowa["EXP_DATE"]);

 

        if ( !empty($email_add) )

        {

          $msgattach = '"'. str_pad( $item, 20, " ") . '","˜' . str_pad( $apn, 14, " ") . '",' . $dsc . ',' . trim(str_pad ($rowa["PRICE"],12, " " )).','. $expdate .','. $rowa["SOURCE"] .chr(13). chr(10);

          fwrite ($handle, $msgattach);

        }

 

        echo "<tr><td bgcolor=#$color style=\"text-align: center; font-size: 10pt\">".$expdate ."</td></tr>";

 

I have trimmed it for clarity. But there is nothing else between the if and the echo of the last line. Any ideas? it's really got me stumped! The email attachment gets '2008-03-31' but the display of the webpage is '2009-03-31' which is correct

Link to comment
https://forums.phpfreaks.com/topic/104298-bizarre-variable-problem/
Share on other sites

        $expdate = end_period($rowa["EXP_DATE"]);

        if ( !empty($email_add) ) 
        {
           $msgattach = '"'. str_pad( $item, 20, " ") . '","˜' . str_pad( $apn, 14, " ") . '",' . $dsc . ',' . trim(str_pad ($rowa["PRICE"],12, " " )).','. $expdate .','. $rowa["SOURCE"] .chr(13). chr(10);
           fwrite ($handle, $msgattach);
        }

        echo "<tr> <td bgcolor=#$color style=\"text-align: center; font-size: 10pt\">".$rowa["ITEM"] ."</td>". 
                  "<td bgcolor=#$color style=\"text-align: center; font-size: 10pt\">".$apn ."</td>". 
                  "<td bgcolor=#$color style=\"text-align: center; font-size: 10pt\">".$rowa["ITEM_DESC"] ."</td>". 
                  "<td bgcolor=#$color style=\"text-align: center; font-size: 10pt\">".$rowa["PRICE"] ."</td>".                   
                  "<td bgcolor=#$color style=\"text-align: center; font-size: 10pt\">".$expdate ."</td>".
                  "<td bgcolor=#$color style=\"text-align: center; font-size: 10pt\">".$rowa["SOURCE"] ."</td></tr>";

 

There it all is then :) I am not a muntz and understand the concept is ridiculous. I'm naturally a C++ coder and PHP is a bit new, but logically it just doesn't make sense as to why the variable changes.

Before: 2009-03-31

After: 2009-03-31

 

Indeed it is incredibly strange, hence why I thought there just has to be some strange thing I have overlooked in PHP! I just can't understand how it could print 2008-03-31 in the email instead. The only way that would happen is if for some reason I called the end_period() again and it was for whatever reason going down the path where it was in the first 3 months of the year and so set the year to 2008. But it's not, and the code before I came and added the $expdate variable did call the function in both places it wanted to use it so it was my first thought. I really have nfi.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.