Migration to PHP 4.4.2 breaks application

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeffcdo
Forum Newbie
Posts: 7
Joined: Fri Feb 22, 2008 12:38 pm

Migration to PHP 4.4.2 breaks application

Post by jeffcdo »

My site recently changed it's version of PHP from 4.3.2 to 4.4.2, and in doing so was moved from one server to another. Unfortunately this seems to have broken several of my scripts. I'm running PHPBB3 which is working fine, and Gallery2 which is working fine, however the following bit of code is one example which used to successfully query a database but now fails to return a result under 4.4.2:

Code: Select all

<?
include"lib/common.php";
        $sql1='select articles_table.id, DATE_FORMAT(articles_table.date, "%b %d %Y") as formatted_date, articles_table.publication, articles_table.title, articles_table.author
                   from articles_table
                   order by articles_table.date asc';
    $res1=mysql_query($sql1);
    $count=0;
    $year=$_GET[year];
    print "<table width=\"auto\" border=\"0\" align=\"center\" cellpadding=\"4\" cellspacing=\"0\" valign=\"top\" >";
    while($row=@mysql_fetch_array($res1))
    {
    $dat=$row[formatted_date];
    $dat=substr($dat,7);
    if ($dat==$year && isset($row[id]))
    {
    print "<tr valign=top class=\"firstnormal\"><td nowrap>$row[formatted_date]</td><td>$row[publication]</td><td><a href=\"articletext.php?articleid=$row[id]\">$row[title]</a></td>
    <td>by $row[author]</td></tr>";
    }
    $row=@mysql_fetch_array($res1);
    $dat=$row[formatted_date];
    $dat=substr($dat,7);
    if($dat==$year && isset($row[id]))
    {
    print "<tr valign=top class=\"secondnormal\"><td nowrap>$row[formatted_date]</td><td>$row[publication]</td><td><a href=\"articletext.php?articleid=$row[id]\">$row[title]</a></td>
    <td>by $row[author]</td></tr>";
    }
 
    }
    print"<tr class=\"input\" align=\"center\"><td colspan=\"5\"></td></tr></table>";
 
?></td>
 
-----------------------------------
The link to this page can be found here
http://www.marshallcrenshaw.com/venue.php?venueid=62
Before the switch to 4.4.2 this returned the text of an article from a database. I have several support requests in with my host but they seem unable to solve the problem. My question is, is there something about the above bit of code that is now incompatible with PHP 4.4.2 ?
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.

Mod | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by jeffcdo on Fri Feb 22, 2008 5:29 pm, edited 3 times in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Migration to PHP 4.42 breaks application

Post by RobertGonzalez »

My first recommendation is to use regular opening PHP tags instead of short open tags. If that doesn't solve it, a check of the ini settings may help:

Code: Select all

<?php
echo '<pre>', print_r(ini_get_all(), 1), '</pre>';
?>
jeffcdo
Forum Newbie
Posts: 7
Joined: Fri Feb 22, 2008 12:38 pm

Re: Migration to PHP 4.4.2 breaks application

Post by jeffcdo »

Here's that script on my server but I'm not sure how to interpet the results..

http://www.marshallcrenshaw.com/initest.php

Also server config..

http://www.marshallcrenshaw.com/phpinfo.php
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Migration to PHP 4.42 breaks application

Post by RobertGonzalez »

The code you posted and the page you reference appear to be two different things. The link accepts a $_GET var of venue while the code you posted does not reference a venue var anywhere. If you can, try to change the code to this and see if it works:

Code: Select all

<?php
include 'lib/common.php';
        $sql1='select articles_table.id, DATE_FORMAT(articles_table.date, "%b %d %Y") as formatted_date, articles_table.publication, articles_table.title, articles_table.author
                  from articles_table
                  order by articles_table.date asc';
    $res1=mysql_query($sql1);
    $count=0;
    $year=$_GET['year'];
    print '<table width="auto" border="0" align="center" cellpadding="4" cellspacing="0" valign="top">';
    while($row = mysql_fetch_array($res1))
    {
    $dat=$row['formatted_date'];
    $dat=substr($dat,7);
    if ($dat==$year && isset($row['id']))
    {
    print '<tr valign=top class="firstnormal"><td nowrap>' . $row['formatted_date'] . '</td><td>' . $row['publication'] . '</td><td><a href="articletext.php?articleid=' . $row['id'] . '">' . $row['title'] . '</a></td>
   <td>by ' . $row['author'] . '</td></tr>';
    }
    $row = mysql_fetch_array($res1);
    $dat=$row['formatted_date'];
    $dat=substr($dat,7);
    if($dat==$year && isset($row['id']))
    {
    print '<tr valign=top class="secondnormal"><td nowrap>'.$row['formatted_date'].'</td><td>'.$row['publication'].'</td><td><a href="articletext.php?articleid='.$row['id'].'">'.$row['title'].'</a></td>
   <td>by '.$row['author'].'</td></tr>';
    }
 
    }
    print '<tr class="input" align="center"><td colspan="5"></td></tr></table>';
 
?></td>
See if this does anything different. If you still have problems try adding the following line to the beginning of the script:

Code: Select all

<?php
ini_set('display_errors', 1);
?>
Then run it again and see what comes to the screen.
jeffcdo
Forum Newbie
Posts: 7
Joined: Fri Feb 22, 2008 12:38 pm

Re: Migration to PHP 4.4.2 breaks application

Post by jeffcdo »

I'm sorry the above code refererences the following link:

http://www.marshallcrenshaw.com/article ... icleid=122
jeffcdo
Forum Newbie
Posts: 7
Joined: Fri Feb 22, 2008 12:38 pm

Re: Migration to PHP 4.4.2 breaks application

Post by jeffcdo »

Adding your troubleshooting line of code returns a variable not found error. It seems like using $_GET var has somehow broken.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Migration to PHP 4.4.2 breaks application

Post by RobertGonzalez »

Your code is looking for a get var named year. Neither of the links you posted are passing a GET var named year. Perhaps using a little bit of isset() would help in this case.
jeffcdo
Forum Newbie
Posts: 7
Joined: Fri Feb 22, 2008 12:38 pm

Re: Migration to PHP 4.4.2 breaks application

Post by jeffcdo »

Ok I've cleaned things up, sorry for the confusing jumble above. Here's the new code:

Code: Select all

   <?php
        ini_set('display_errors', 1);
        include"lib/common.php";
        $articleid=isset($_GET["articleid"]) ? $_GET["articleid"] : "";
        $sql1="select * from articles_table where 'id' ='$articleid'";
    $res1=mysql_query($sql1);
    print "<table width=\"auto\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\" valign=\"top\">";
    if($row=mysql_fetch_array($res1))
    {
            print "<tr><td><h3>$row[title]</h3></td></tr>";
        print "<tr><td><em><img src=\"images/spacer.jpg\" width=\"5\" height=\"1\" />by $row[author]</em></td></tr>";
        print "<tr><td><em><img src=\"images/spacer.jpg\" width=\"5\" height=\"1\" />$row[publication]</em></td></tr>";
        print "<tr><td><img src=\"images/spacer.jpg\" width=\"5\" height=\"1\" />$row[date]</td></tr>";
        print "<tr><td>&nbsp;</td></tr>";
        print "<tr><td>$row[body]</td></tr>";
                print "<tr><td> </td></tr>";
        print"<tr class=\"input\" align=\"center\"><td colspan=\"2\"><input type=\"submit\" value=\"Back\" onClick=\"history.back(-1)\"></td></tr></table>";
 
    }
    else
        print"Sorry, no record for that article on file.";
?>
And this is the result:

http://www.marshallcrenshaw.com/article ... icleid=122
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Migration to PHP 4.4.2 breaks application

Post by RobertGonzalez »

I'm heading out for the day. Last suggestion:

Take this line:

Code: Select all

<?php
if($row=mysql_fetch_array($res1))
?>
And just inside the if block, var_dump($row). See what it is throwing back.
jeffcdo
Forum Newbie
Posts: 7
Joined: Fri Feb 22, 2008 12:38 pm

Re: Migration to PHP 4.4.2 breaks application

Post by jeffcdo »

I think I figured it out, it was the register_globals value defaulting to "off" in the newer version of PHP. I added a line like this for each variable in my broken scripts:

Code: Select all

  $variable=isset($_GET["variable"]) ? $_GET["variable"] : "";
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Migration to PHP 4.4.2 breaks application

Post by RobertGonzalez »

That would do it. Glad you got it sorted.
jeffcdo
Forum Newbie
Posts: 7
Joined: Fri Feb 22, 2008 12:38 pm

Re: Migration to PHP 4.4.2 breaks application

Post by jeffcdo »

Thank you for your help and patience!
Post Reply