Jump to content

PHP 4 to 5 migration issue


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

 

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.