pelowe Posted January 9, 2009 Share Posted January 9, 2009 After migrating from PHP 4.3.10 to 5.2.8 I'm receiving an "undefined index" error from the following code... <?php while($row = mysql_fetch_array($result)){?> <input id="yard_<?php echo $row['yard_id'];?>" type="checkbox" name="yard_list[]" value="<?php echo $row['yard_id'];?>" checked> <label for="yard_<?php echo $row['yard_id'];?>"><?php echo $row['yard'];?></label><br> <?php }?> I know the mysql result is valid since it works fine in PHP4. I realize this is a little messy and should have been written a little neater. But it is old code that I wrote long ago. My problem is I have this style of coding sprinkled throughout my apps and it would be a real task to find every occurrence of it. Thanks Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 9, 2009 Share Posted January 9, 2009 if you weren't getting that before, then your configuration was set to ignore NOTICEs...which in most cases is fine. to set it again on the new install, find the error_reporting line in your php.ini and set it to: error_reporting = E_ALL & ~E_NOTICE on a side note...you are getting the notice because yard_id or yard is not a key in the $row array. this in turn means you aren't selecting that column or the column doesn't exist in your table. what is the SQL for this? and what is your table structure? try doing a print_r($row) in the loop to see if the key/value pairs are correct Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2009 Share Posted January 9, 2009 I'll second that. If $row['yard_id'] and/or $row['yard'] are producing an "undefined index" error then the posted code is not producing the output you expect. Hiding the notice message will mean that the code is not producing the output you expect and you are not being notified that the problem exists. If the output is missing $row['yard_id'] and/or $row['yard'] then it means that something else changed during the upgrade and your query is no longer selecting the data you expect or that the error is referring to something else or is being caused by other code in that while() loop that you have not posted. Quote Link to comment Share on other sites More sharing options...
pelowe Posted January 9, 2009 Author Share Posted January 9, 2009 This is my dev server so I have all error turned on in both PHP4 and 5 configs. I don't have the query right in front of me but from memory I know it's pretty simple. Something like: SELECT yard, yard_id FROM yard; It just grabs the yard names (this is for a bus company) and there respective id's. And as I said it works in PHP4 So I was thinking it was some kind of syntax issue. But I haven't read or seen anything on the web that indicates any syntax backward-compatibility issues. Thanks Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 9, 2009 Share Posted January 9, 2009 there is nothing there that should change from 4 to 5. if you post more code we might be able to spot the issue Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2009 Share Posted January 9, 2009 To help without a lot of off topic guesses, we would need the table definition, the actual query, the actual error message, and the actual code from the query through to the end of the while() loop and if this happens to be inside of another query loop, just post all the code to save time. Edit: Also what operating system is this. Quote Link to comment Share on other sites More sharing options...
pelowe Posted January 9, 2009 Author Share Posted January 9, 2009 I'll have to get further code tonight as this is a side job and I don't have access from my day job. But to answer the operating system question, it is Windows 2003 > Apache 2.x > MySQL 3.x Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 9, 2009 Share Posted January 9, 2009 MySQL 3.x !! wow, time to upgrade.... Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2009 Share Posted January 9, 2009 And that could very well explain why the query appears to be executing (the code in the while() loop being executed) but the fetched data does not contain column(s). The mysql client library was updated when you updated php versions. If by chance a change was made or something was not fully tested with such an older version of mysql, it could be the cause of the problem. Quote Link to comment Share on other sites More sharing options...
pelowe Posted January 10, 2009 Author Share Posted January 10, 2009 The output from var_dump($row) is: PHP4 array(2) { ["yard"]=> string(22) "Chestnut Ridge Transit" ["yard_id"]=> string(1) "5" } PHP5 array(2) { [""]=> string(22) "Chestnut Ridge Transit" ["B"]=> string(1) "5" } Why would I be getting the strange characters for the field values? Quote Link to comment Share on other sites More sharing options...
pelowe Posted January 10, 2009 Author Share Posted January 10, 2009 Tried changing the Collation on the MySQL table to utf8_bin And all works well. It's only a development MySql server so I wasn't worried about breaking the live applications. I'm not to familiar with the Collation settings in MySql so I'll need to do some heavy research before make that change across the entire db. Any help on that topic would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 10, 2009 Share Posted January 10, 2009 The newer php client libraries support a character set settings. I'm going to guess that the newer php client libraries cannot detect or interface with the character set setting in mysql3. 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.