Zonkel Posted May 6, 2008 Share Posted May 6, 2008 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 More sharing options...
AndyB Posted May 6, 2008 Share Posted May 6, 2008 Based on your 'trimmed for clarity' code you're claiming that $expdate has one value the first time it's used (in $msgattach) and a different value the next time it's used (in the table cell)? I'm skeptical! Link to comment https://forums.phpfreaks.com/topic/104298-bizarre-variable-problem/#findComment-534023 Share on other sites More sharing options...
Zonkel Posted May 6, 2008 Author Share Posted May 6, 2008 $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. Link to comment https://forums.phpfreaks.com/topic/104298-bizarre-variable-problem/#findComment-534024 Share on other sites More sharing options...
DarkWater Posted May 6, 2008 Share Posted May 6, 2008 What does end_period() do? Link to comment https://forums.phpfreaks.com/topic/104298-bizarre-variable-problem/#findComment-534049 Share on other sites More sharing options...
Zonkel Posted May 6, 2008 Author Share Posted May 6, 2008 Unimportant, but as you ask it just returns the variable passed to it unless the year in the date is '9999' in which case it will set the date to the end of the next march. It works correctly, as the correct value is displayed in the web browser. Just not the email. Link to comment https://forums.phpfreaks.com/topic/104298-bizarre-variable-problem/#findComment-534052 Share on other sites More sharing options...
DarkWater Posted May 6, 2008 Share Posted May 6, 2008 That's REALLY strange. Do me a favor. Echo out the $expdate BEFORE the mail block and AFTER the mail block and tell me the outputs. Link to comment https://forums.phpfreaks.com/topic/104298-bizarre-variable-problem/#findComment-534067 Share on other sites More sharing options...
Zonkel Posted May 6, 2008 Author Share Posted May 6, 2008 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. Link to comment https://forums.phpfreaks.com/topic/104298-bizarre-variable-problem/#findComment-534075 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.