Butterbean Posted January 10, 2015 Share Posted January 10, 2015 (edited) With a prior version of Php, this code was acceptable. $query = sqlsrv_query($conn, $sql);if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){ $sumUsageKWH += $row[totalUsage];}sqlsrv_free_stmt($query);?> Now, with php 5.6.3, I have to add a couple of things. $query = sqlsrv_query($conn, $sql);if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){ $sumUsageKWH += $row['totalUsage'];}sqlsrv_free_stmt($query);?> due to an error prompt. Once I make the corrections, I have a new errors all over the place. Is there a difference in defining a variable with 5.6.3? Edited January 10, 2015 by Butterbean Quote Link to comment Share on other sites More sharing options...
Butterbean Posted January 10, 2015 Author Share Posted January 10, 2015 Here are some errors that were perfectly fine with a previous version of PHP.. Notice: Undefined variable: sumUsageKWH in C:\xampp1\htdocs\Utrack\invoice.php on line 71Notice: Undefined variable: sumUsageWKWi in C:\xampp1\htdocs\Utrack\invoice.php on line 146Notice: Undefined variable: sumUsageWKWp in C:\xampp1\htdocs\Utrack\invoice.php on line 168Notice: Use of undefined constant meter_multiplier - assumed 'meter_multiplier' in C:\xampp1\htdocs\Utrack\invoice.php on line303Notice: Undefined variable: meter_multiplier in C:\xampp1\htdocs\Utrack\invoice.php on line 303Notice: Use of undefined constant raw_material_price - assumed 'raw_material_price' in C:\xampp1\htdocs\Utrack\invoice.phpon line 303Notice: Undefined variable: raw_material_price in C:\xampp1\htdocs\Utrack\invoice.php on line 303Notice: Use of undefined constant basic_charge - assumed 'basic_charge' in C:\xampp1\htdocs\Utrack\invoice.php on line 303Notice: Undefined variable: basic_charge in C:\xampp1\htdocs\Utrack\invoice.php on line 303 Quote Link to comment Share on other sites More sharing options...
Butterbean Posted January 10, 2015 Author Share Posted January 10, 2015 I would assume no one wants to plow through 500 lines of code but I would be more than happy to post if it you like. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted January 10, 2015 Share Posted January 10, 2015 The first code was never acceptable in any PHP version. You just had the error reporting turned off, so PHP didn't tell you about the issues. Whether you want to actually fix the coding style or simply silence PHP again is up to you. 1 Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted January 10, 2015 Solution Share Posted January 10, 2015 variables definitions have not changed in php since day one. the errors you are seeing were likely always present, but were being hidden by the error_reporting/display_errors settings where the code was being ran at. the undefined variable messages were explained in one of your previous threads, you are referencing a variable that doesn't yet exist. in the case of the += operator, you were shown how to define the variable before the start of the loop to prevent the error. for the Notice: Use of undefined constant meter_multiplier - assumed 'meter_multiplier' type of messages, that's because the code doesn't have the needed single quotes around the associate array index names, making php think you are using a defined constant as the index name, then when it doesn't find a defined constant by that name, it assumes you meant to supply a string, all taking up about 5 times more processing than if the code had been written correctly. both of these problems are because whoever originally wrote the code took short-cuts that saved a little typing (but was probably producing giga-byte size error log files.) the way to fix the errors is to do the work now that the original programmer left out of properly initializing variables and of putting quotes around things that are strings. Quote Link to comment Share on other sites More sharing options...
Butterbean Posted January 10, 2015 Author Share Posted January 10, 2015 That is very good to know. Thank you both for the help. Quote Link to comment 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.