Page 1 of 2

script failing not sure why

Posted: Tue Feb 01, 2005 3:46 am
by SFADuncan
Script failing, not sure why

Hello Pros...

This amateur is having trouble again!

The site is http://www.ealingcc.co.uk which is based on PHP and a MySQL database.

Content is delieverd by finding out the directory and delivering the correct data accordingly. Most of the time it works... but every ten or so clicks it fails.... the script is below (the comment below in bold is where it occasionally seems to fail)... any ideas?

quote:
/* this section gets the directory and delivers content based on it... ie cricket, facilities etc Seems to work*/


<?

if (!session_is_registered("output"))
{
session_register("output");
}

$pwd = pathinfo(getcwd());
$directory = $pwd['basename'];
$output = $directory;

/* my functions etc */
require ("../funcs/variables.php");
require("../funcs/funcs_display.php");
require("../funcs/modules_display.php");
require("../funcs/db_funcs.php");
?>

<html>
<head>

<title><? echo $browser_title ?></title>
<LINK REL="STYLESHEET" TYPE="text/css" HREF="../temp_01/cssfile.css">
</head>


/* this bit gets the page type, and this is the bit causing trouble, sometimes it doesn't seem to work */

<?php

$pgtype_array = get_www($output);

if (!is_array($pgtype_array))
{
echo 'Nothing to display';
return;
}
foreach ($pgtype_array as $row)
{
$pgtype1 = $row['pgtype1'];
$pgtype2 = $row['pgtype2'];
$pgtype3 = $row['pgtype3'];
$pgtype4 = $row['pgtype4'];
$pgtype5 = $row['pgtype5'];
}



/* and this bit gets the content based on the page type, which obviously fails if the above fails */


if ($pgtype1 == 'md1')
{
require ("../temp_01/tm_01_header_01.php");

$title1_array = get_www($output);
extract_mod1_title1($title1_array);

$page1_array = get_www($output);
extract_mod1_text1($page1_array);

require ("../temp_01/tm_01_footer_01.php");
exit;
}



if ($pgtype1 == 'md2')
{
require("../temp_01/tm_01_header_02.php");

$title1_array = get_www($output);
extract_mod2_title1($title1_array);

$page1_array = get_www($output);
extract_mod2_text1($page1_array);

require("../temp_01/tm_01_footer_02.php");
exit;
}


if ($pgtype1 == 'md3')


etc etc etc

Posted: Tue Feb 01, 2005 4:52 am
by JayBird
Do you get any error message?

Posted: Tue Feb 01, 2005 5:01 am
by SFADuncan
I've just edited the code so that the error message is phpinfo(). But I was getting the error message which appears in the second part of the code: "Nothing to display" quite frequently.

Image here: http://www.ealingcc.co.uk/test/error.jpg

But it doesn't seem to happen to all users and all browsers. A colleague of mine has only seen this error message once (he works from a different location)

I was wondering whether or not I'm asking the server to do too much ie on every page refresh, to go away find out what page type it is and then publsih accordingly. When I take out the page type routine from all pages, put it in a separate page, and then run a routine which uses include (not require) to bring it in, it happens even less to other browsers (but still occurs to me (XP, IE6, SP2 etc). Not sure why.

Simon

Posted: Tue Feb 01, 2005 5:10 am
by JayBird
I was just having a quick go an i never got the error message you mention.

Instead, what i do get is every so often, i get the results of

phpinfo();


Strangley!?!

Posted: Tue Feb 01, 2005 5:11 am
by SFADuncan
Yeah.. really sorry... a mate of mine who is unable to help me suggested I put in phpinfo(); as the error message as it might reveal more info.... but it's beyond me....

Any ideas..?

Simon

Posted: Tue Feb 01, 2005 5:19 am
by JayBird
obviously for some reason, $pgtype_array is no longer an array.

how do you set $pgtype_array

Posted: Tue Feb 01, 2005 5:21 am
by Wayne
what does the code for get_www() look like?

Posted: Tue Feb 01, 2005 5:29 am
by SFADuncan
These (below) are examples of the other bits of code to which my original example refers.... (although http://www.ealingcc.co.uk is a 5 page website, it's configured to cope with 12 pages... eg http://www.mountcarmelschool.org.uk/home/index.php (which uses the same code, but which I've not yet encountered the error on although same MySQL db setiings, permissions etc))

function get_www($output)
{
$conn = db_connect();
$query = "select * from www where http://www.wwwname = '$output'";
$result = @mysql_query($query);
if (!$result)
return false;
$num_cats = @mysql_num_rows($result);
if ($num_cats ==0)
return false;
$result = db_result_to_array($result);
return $result;
}



function extract_mod1_title1($title1_array)
{
if (!is_array($title1_array))
{
echo 'error';
return;
}
foreach ($title1_array as $row)
{
$title1 = $row['title1'];

display_mod1_title($title1, $title2, $title3, $title4, $title5, $title6, $title7, $title8, $title9, $title10, $title11, $title12);
}
}



function display_mod1_title($title1, $title2, $title3, $title4, $title5, $title6, $title7, $title8, $title9, $title10, $title11, $title12)
{
if (isset($title1)) print nl2br('<p align="justify"><FONT CLASS="font1">'.$title1.'</p>');
if (isset($title2)) print nl2br('<p align="justify"><FONT CLASS="font1">'.$title2.'</p>');
if (isset($title3)) print nl2br('<p align="justify"><FONT CLASS="font1">'.$title3.'</p>');
if (isset($title4)) print nl2br('<p align="justify"><FONT CLASS="font1">'.$title4.'</p>');
if (isset($title5)) print nl2br('<p align="justify"><FONT CLASS="font1">'.$title5.'</p>');
}

Posted: Tue Feb 01, 2005 5:34 am
by Wayne
have you tried removing the @ from the mysql_... lines, see if you get any errors from that

Posted: Tue Feb 01, 2005 5:34 am
by SFADuncan
Each index page looks like this... :

Code: Select all

<?php
include ("../temp_01/display.php");

$pgtype_array = get_www($output);
include ("../temp_01/page_01.php");
?>

... the above is index.php...

page_01.php has the stuff I included originally...

Code: Select all

<?php
include ("../funcs/pgtype.php");

if ($pgtype1 == 'md1')
&#123;
include ("../temp_01/tm_01_header_01.php");

$title1_array = get_www($output);
extract_mod1_title1($title1_array);

$page1_array = get_www($output);
extract_mod1_text1($page1_array);

include ("../temp_01/tm_01_footer_01.php");
exit;
&#125;

if ($pgtype1 == 'md2')

etc

Posted: Tue Feb 01, 2005 5:48 am
by SFADuncan
Hi...

have just removed the @ from the mysql_... lines...

(what does that do by the way? No idea!)

Things seem to have improved.... I had to click around for quite some time before I got the error again... but I did get it eventually....

Simon

Posted: Tue Feb 01, 2005 5:49 am
by JayBird
when you put an @ before the MySQL funstion, it supresses an error message.

Wayne was saying remove it to see if your query was returning any errors

Posted: Tue Feb 01, 2005 5:55 am
by JayBird
also, should you not have session_start(); at the begining of your script?

Posted: Tue Feb 01, 2005 5:59 am
by SFADuncan
Not sure... let me know...

1st thing each page has is:

Code: Select all

include ("../temp_01/display.php");
display.php opens with:

Code: Select all

if (!session_is_registered("output")) 
&#123;
session_register("output");
&#125;

$pwd = pathinfo(getcwd()); 
$directory = $pwd&#1111;'basename']; 
$output = $directory;
This routine isolates the directory in the browser so my stuff can go away and deliver the right info from the db... should it be reconfigured?

Simon

Posted: Tue Feb 01, 2005 6:08 am
by JayBird
im sure you should do this

Code: Select all

session_start();

$pwd = pathinfo(getcwd()); 
$directory = $pwd&#1111;'basename']; 
$output = $directory;

The session_register stuff you are using is old now and been replace. I dont think you need that part of the code at all.

Set session variables by doing

Code: Select all

$_SESSION&#1111;'output'] = "something";