Jump to content

Errors when hosting changed


diddle-diddle

Recommended Posts

Hi all

I've just discovered this site and will be spending lots of time studying so that hopefully I won't have to ask too many questions!  I'm just out of college (as a mature student), having done a little PHP, and I have a site hosted on my college server, running PHP on Apache I believe.  I've ported the site to another hosting company and I'm now getting errors.  The hosting company is using PHP on IIS.  I didn't think that I would have to write the code differently depending on what PHP is being run on, but could this be the case?  The company have given me the equivalent of 777 permissions because I couldn't use CHMOD seeing that it is Windows .... the things they don't teach you in college eh!

The site is [url=http://www.stlouisschool.net]www.stlouisschool.net[/url].  You will see errors on the index page, and then on the contact page when you go to send the mail. 

The errors on the index page refer I believe, to an offset I have to ensure that the XML feed I'm pulling from sends the latest 5 news stories and not the oldest ones.  The errors when sending the contact form appear to be from variables not being picked up from the form, but they're all perfect on my college server!

I have a phpinfo.php page on the .net hosting if you need any more information about it.

Sorry if this is very basic, but I've spent hours trying to investigate before posting and can't find anything ... not sure what to even be looking for tho!

Hope you can help, I'm very bewildered at these errors  ???

Diddle 
Link to comment
https://forums.phpfreaks.com/topic/31383-errors-when-hosting-changed/
Share on other sites

The errors on the page look like you are trying to access array elements that are not there...hence the "Undefined Offset." Check the line numbers that the errors report and see if your array has the content that it should. I usually get these when I forget to error check a DB query and try to access the results array which, of course, would have nothing in them.
Hi and thanks for your help

There is code at the start of the page to open the XML feed that the script should be pulling from, it defines variables and parses the XML. 
This is the relevant code:

[code]if( ! ($fp = fopen( "./louisnews.xml" , "r" )) )
  die("Couldn't open xml file!");
$person_counter = 0;
$person_data = array();
$xml_current_tag_state = '';
function startElementHandler( $parser, $element_name, $element_attribs )
{
  global $person_counter;
  global $person_data;
  global $xml_current_tag_state;
  if( $element_name == "STORY" )
  {
    $person_data[$person_counter]["author"] = $element_attribs["AUTHOR"];
  }
  else
  {
    $xml_current_tag_state = $element_name;
  }
}
function endElementHandler( $parser, $element_name )
{
  global $person_counter;
  global $person_data;
  global $xml_current_tag_state;
  $xml_current_tag_state = '';
  if( $element_name == "STORY" )
  {
    $person_counter++;
  }
}
function characterDataHandler( $parser , $data )
{
  global $person_counter;
  global $person_data;
  global $xml_current_tag_state;
  if( $xml_current_tag_state == '' )
    return;
if( $xml_current_tag_state == "STORYTYPE" ) {
    $person_data[$person_counter]["storytype"] = $data;
  }

  if( $xml_current_tag_state == "HEADLINE" ) {
    $person_data[$person_counter]["headline"] = $data;
  }
  if( $xml_current_tag_state == "ABSTRACT" ) {
    $person_data[$person_counter]["abstract"] = $data;
  }
  if( $xml_current_tag_state == "DATE" ) {
    $person_data[$person_counter]["date"] = $data;
  }
  if( $xml_current_tag_state == "BODYTEXT" ) {
    $person_data[$person_counter]["bodytext"] = $data;
  }
  if( $xml_current_tag_state == "STORYLINK" ) {
    $person_data[$person_counter]["storylink"] = $data;
  }
}
[/code]

This is working perfectly on my college hosting - I have a page called inputnews.php that sends data to the XML file and then on the index.php page, the newest 5 stories get fed in.  You can see how it's meant to work on:
[url=http://student.dcu.ie/~morgant2/stlouis/index.php]http://student.dcu.ie/~morgant2/stlouis/index.php[/url]

The code that displays the news stories is basically as follows:

[code]$storylink1 = $person_data[count($person_data) -1]["storylink"];

echo "<h3 class=\"date\">";
echo $person_data[count($person_data) -1]["date"] ;
echo "</h3>";
echo "<h4 class=\"news\">";
echo $person_data[count($person_data) -1]["headline"] ;
echo "</h4><p class=\"news\">";
echo $person_data[count($person_data) -1]["abstract"] ;
[/code]

The errors on the page say: [b]Notice: Undefined offset: -1 in d:\webspace\admin\stlouisschool.net\WWW\index.php on line 123[/b] and subsequent errors are similar.

In relation to the code trying to access array elements that are not there - would this cause errors on one system and not on another?  Sorry if this is basic but I assumed that if I tested on my college space it would be relatively easily ported to another system.  ???  If there's a bigger issue of me being completely clueless when it comes to PHP on IIS I'd like to be aware of that so that I can learn how PHP functions on different systems.

Thanks again

Diddle
Hi Thorpe and thanks

I didn't know about error reporting at all ... there must be a default on the college server to suppress errors and that's why everything seemed fine there ... in future I'll make sure to turn all reporting on when testing so that I get better feedback.

Thanks again for your help, I guess I've lots to learn  :)  Better get working!

Diddle

Archived

This topic is now archived and is closed to further replies.

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