script failing not sure why
Moderator: General Moderators
script failing not sure why
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
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
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
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
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>');
}
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>');
}
Each index page looks like this... :
... the above is index.php...
page_01.php has the stuff I included originally...
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')
{
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;
}
if ($pgtype1 == 'md2')
etcNot sure... let me know...
1st thing each page has is:
display.php opens with:
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
1st thing each page has is:
Code: Select all
include ("../temp_01/display.php");Code: Select all
if (!session_is_registered("output"))
{
session_register("output");
}
$pwd = pathinfo(getcwd());
$directory = $pwdї'basename'];
$output = $directory;Simon
im sure you should do this
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_start();
$pwd = pathinfo(getcwd());
$directory = $pwdї'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ї'output'] = "something";