PDA

View Full Version : why does this php page only work sometimes ?


rseidl
09-17-2003, 03:51 PM
<noob-alert />

I am trying to do my first DB fetches from a web page (.../forum/example.php) and am using this code:


<html><head></head><body>

<?php
error_reporting(7);
echo("Latest posts<p>");
include( "global.php");
$latestthread=$DB_site->query("SELECT title,threadid,dateline FROM thread ORDER BY dateline DESC LIMIT 20");
while ($latestthreads=$DB_site->fetch_array($latestthread)) {
echo ("$latestthreads[title]<br>");
}
?>

</body></html>


Now the strange thing is it only works sometimes, at other times I get a standard error template (including some goobledigook about being "Unable to add cookies, header already sent") back from PHP which I assume means it could not get the data for some reason ?
Perhaps relevant: the forum directory is a passworded realm for my apache server, but IE correctly asks me for the pw/login for example2.php


(I have a feeling it is the include("global.php") statement that is bombing, since taking everything else but that away i still get the error)

The server is running on Win2K, and I am browsing from an XP HE/IE 6 client.

Thanks
Robert

halo
09-18-2003, 11:20 PM
try,


<?php
require( "global.php");
?>

im not sure if that is the right require code but i will check l8r when i have time

Link14716
09-19-2003, 01:11 AM
<noob-alert />

I am trying to do my first DB fetches from a web page (.../forum/example.php) and am using this code:


<html><head></head><body>

<?php
error_reporting(7);
echo("Latest posts<p>");
include( "global.php");
$latestthread=$DB_site->query("SELECT title,threadid,dateline FROM thread ORDER BY dateline DESC LIMIT 20");
while ($latestthreads=$DB_site->fetch_array($latestthread)) {
echo ("$latestthreads[title]<br>");
}
?>

</body></html>


Now the strange thing is it only works sometimes, at other times I get a standard error template (including some goobledigook about being "Unable to add cookies, header already sent") back from PHP which I assume means it could not get the data for some reason ?
Perhaps relevant: the forum directory is a passworded realm for my apache server, but IE correctly asks me for the pw/login for example2.php


(I have a feeling it is the include("global.php") statement that is bombing, since taking everything else but that away i still get the error)

The server is running on Win2K, and I am browsing from an XP HE/IE 6 client.

Thanks
Robert
Use this:
<?php
require('./global.php');
?>

<html><head></head><body>

<?php
error_reporting(7);
echo("Latest posts<p>");
$latestthread=$DB_site->query("SELECT title,threadid,dateline FROM thread ORDER BY dateline DESC LIMIT 20");
while ($latestthreads=$DB_site->fetch_array($latestthread)) {
echo ("$latestthreads[title]<br>");
}
?>

rseidl
09-19-2003, 03:19 PM
Thanks guys, that was it !

I guess the global.php has to come before any HTML.