SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member pelowe's Avatar
    Join Date
    Sep 2002
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP 4 to 5 migration issue

    After migrating from PHP 4.3.10 to 5.2.8 I'm receiving an "undefined index" error from the following code...

    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

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    var_dump($row); 
    What's the output?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Member pelowe's Avatar
    Join Date
    Sep 2002
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    SitePoint Member pelowe's Avatar
    Join Date
    Sep 2002
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'd ask the guys in the MySQL/Databases forum - you'll get more on that matter than you could here.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •