Jump to content

Trying to Include a PHP File


inkzoid

Recommended Posts

I've got a comment box that is functioning correctly and is set up to a database to retrieve and display comments, but what I am trying to do is place it on a different page.

 

I want it on my gallery.php page, and when I try to include it, I get one of those header errors because it isn't included immediately on line 1. I know I can solve the problem by including it on line 1, but I want my comment box somewhere else down the page and don't know what I have to do to put it somewhere else.

 

<?php 
@session_start();
// calling session_start() the function which starts our authentication session


// connecting to mysql server
$l = mysql_connect  ( "999.999.999.999" , "inkzoid" , "999" ) or die("Error connecting:<BR><BR>".mysql_error());
mysql_select_db( "inkzoid" ) or die("Error getting db:<BR><BR>".mysql_error());
// defining getShouts() which is our function that gets all of our shouts
function getShouts()
{

echo '<div align="left">
	<table width="800" bgcolor="#128911" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td>
';	

$query = mysql_query("SELECT * FROM shouts ORDER BY id DESC LIMIT 10") or die(mysql_error());
while ($row = mysql_fetch_array($query) )
{
	//print_r($row);
	$name = stripslashes($row['name']);
	$contact = stripslashes($row['contact']);
	$shout = stripslashes($row['shout']);

	if(empty($contact))
	{

		echo '<p><span class="author">'.$name.'</span> - <span class="shout">'.$shout.'</span></p>';

	} else {

		echo '<p><span class="author"><a href="'.$contact.'" target="_blank">'.$name.'</a></span> - <span class="shout">'.$shout.'</span></p>';

	} // if empty contact

} // while row mysqlfetcharray query

echo '<br><br>';

echo '
		</td>
	  </tr>
	  <tr>
		<td height="10"> </td>
		<form name="shout" method="post" action="shout.php">
		  <div align="center">
			<input name="name" type="text" id="name" value="Name" size="25" maxlength="10"><br>
			<input name="contact" type="text" id="contact" value="http://" size="25"><br>
			<input name="message" type="text" id="message" value="Message" size="25"><br>
			<input name="shout" type="submit" id="shout" value="Shout!">
		  </div>
		</form>
		</td>
	  </tr>
	  </table>
	  </div>
	';	

} // function getshouts


// our processing if control statement
if ( isset ( $_POST['shout'] ) )
{

$name = addslashes($_POST['name']);
$contact = addslashes($_POST['contact']);
$message =  $_POST['message'];

if ( ( isset($name) ) && ( isset($message) ) )
{

	// getting smilie list
	$smilies = mysql_query("SELECT * FROM smilies") or die(mysql_error());
	while($get = mysql_fetch_array ($smilies))
	{

		$alt = $get['Alt'];
		$smilie = $get['URL'];

		$message = str_replace( $get['Symbol'] , '<img src="smilies/'.$smilie.'" border="0" width="15" height="15" alt="'.$alt.'">' , $message);
		$themessage = addslashes($message);

		// replacing all smilies

	}

	mysql_query("INSERT INTO shouts (name, contact, shout) VALUES ( '$name' , '$contact' , '$message' )") or die(mysql_error());
	$_SESSION['has_posted'] = 'yes';
	header("Location: http://www.inkzoid.com/shoutbox/shout.php");

	// if required fields aren't empty, process into database

} else {

	echo '<script>alert("Some fields were not filled out!");</script>';
	header("Location: http://www.inkzoid.com/shoutbox/shout.php");

	// if required fields were left empty, show an error dialog

}

}/* else {

echo '<script>alert("Please follow the form to this page.");</script>';
header("Location: http://www.inkzoid.com/shoutbox/shout.php");

// if they weren't even referred from the form, show error dialog and redirect

} // if isset post shout

/* STARTING THE MAIN SCRIPT NOW */

// starting the table

//displaying the shouts
getShouts();


mysql_close($l);


?>

Link to comment
Share on other sites

Header errors have nothing to do with where a file is included.

 

You cannot however have any output sent to the browser prior to calling the header function.

 

This for instance....

 

echo '<script>alert("Some fields were not filled out!");</script>';
header("Location: http://www.inkzoid.com/shoutbox/shout.php");

 

will cause errors because echo sends data to the browser.

Link to comment
Share on other sites

I'm trying to take the comment box and put it at the bottom of my gallery page ( http://www.inkzoid.com/gallery.php ) where the old comment box that I'm currently using is. The error message I'm getting when I try to use the php include function to include the php script in my gallery.php page is a typical header location error. It says:

 

Warning: include(/shoutbox/shout.php) [function.include]: failed to open stream: No such file or directory in D:\Hosting\5612165\html\gallery.php on line 190

Warning: include() [function.include]: Failed opening '/shoutbox/shout.php' for inclusion (include_path='.;C:\php5\pear') in D:\Hosting\5612165\html\gallery.php on line 190

 

I know this is coming up because the session_start(); function of my shoutbox.php file is not the very first line on my gallery page (the whole file is included near the bottom of gallery.php), but if I put the shoutbox.php file at the top of gallery.php using include, then the shoutbox will show up at the top of the page, which is not where I want it to show up.

Link to comment
Share on other sites

Did you bother to read the error message? It has nothing to do with the session_start() nor is it even a header error -

 

No such file or directory

 

The path you are using is not valid. The leading slash / you are using refers to the root of the current hard disk.

Link to comment
Share on other sites

@PFMaBiSmAd - Thanks for pointing out my path error...it has been corrected.

@fortnox007 - I apologize but I'm a beginner to PHP...did you mean I should cut the header line from my shout.php script and paste it before the html in my gallery.php file, or copy and paste it instead?

 

I copied it and put it before the html in gallery.php and got a Firefox error (Firefox has detected that the server is redirecting the request for this address in a way that will never complete).

 

This is what I currently have above the html tag on line 1 of gallery.php:

<?php header("Location: http://www.inkzoid.com/gallery.php"); ?>

Link to comment
Share on other sites

Alright so the header location has been changed to shoutbox/shout.php in the gallery.php file and in the shout.php file the 2 references to header location are shoutbox/shout.php. I have the same error as before. I also go the same error when I changed them both to header location gallery.php . Obviously I am doing something wrong...

Link to comment
Share on other sites

Ok I'm trying to go through in my head thinking what exactly I'm doing wrong here...

My syntax for gallery.php line 1 is correct

In shout.php the header location points to itself (shoutbox/shout.php) and there is no slash at the beginning this time, so the path is correct...

I can get gallery.php to show the shoutbox only and not the rest of the gallery page, so I'm partway there...

 

Link to comment
Share on other sites

Line 1 of gallery.php

<?php header("Location: http://www.inkzoid.com/shoutbox/shout.php"); ?>

 

Here's shoutbox/shout.php:

<?php 
@session_start();
// calling session_start() the function which starts our authentication session


// connecting to mysql server
$l = mysql_connect  ( "999.999.999.999" , "inkzoid" , "999" ) or die("Error connecting:<BR><BR>".mysql_error());
mysql_select_db( "inkzoid" ) or die("Error getting db:<BR><BR>".mysql_error());
// defining getShouts() which is our function that gets all of our shouts
function getShouts()
{

echo '<div align="left">
	<table width="800" bgcolor="#128911" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td>
';	

$query = mysql_query("SELECT * FROM shouts ORDER BY id DESC LIMIT 10") or die(mysql_error());
while ($row = mysql_fetch_array($query) )
{
	//print_r($row);
	$name = stripslashes($row['name']);
	$contact = stripslashes($row['contact']);
	$shout = stripslashes($row['shout']);

	if(empty($contact))
	{

		echo '<p><span class="author">'.$name.'</span> - <span class="shout">'.$shout.'</span></p>';

	} else {

		echo '<p><span class="author"><a href="'.$contact.'" target="_blank">'.$name.'</a></span> - <span class="shout">'.$shout.'</span></p>';

	} // if empty contact

} // while row mysqlfetcharray query

echo '<br><br>';

echo '
		</td>
	  </tr>
	  <tr>
		<td height="10"> </td>
		<form name="shout" method="post" action="shout.php">
		  <div align="center">
			<input name="name" type="text" id="name" value="Name" size="25" maxlength="10"><br>
			<input name="contact" type="text" id="contact" value="http://" size="25"><br>
			<input name="message" type="text" id="message" value="Message" size="25"><br>
			<input name="shout" type="submit" id="shout" value="Shout!">
		  </div>
		</form>
		</td>
	  </tr>
	  </table>
	  </div>
	';	

} // function getshouts


// our processing if control statement
if ( isset ( $_POST['shout'] ) )
{

$name = addslashes($_POST['name']);
$contact = addslashes($_POST['contact']);
$message =  $_POST['message'];

if ( ( isset($name) ) && ( isset($message) ) )
{

	// getting smilie list
	$smilies = mysql_query("SELECT * FROM smilies") or die(mysql_error());
	while($get = mysql_fetch_array ($smilies))
	{

		$alt = $get['Alt'];
		$smilie = $get['URL'];

		$message = str_replace( $get['Symbol'] , '<img src="smilies/'.$smilie.'" border="0" width="15" height="15" alt="'.$alt.'">' , $message);
		$themessage = addslashes($message);

		// replacing all smilies

	}

	mysql_query("INSERT INTO shouts (name, contact, shout) VALUES ( '$name' , '$contact' , '$message' )") or die(mysql_error());
	$_SESSION['has_posted'] = 'yes';
	header("Location: http://www.inkzoid.com/shoutbox/shout.php");

	// if required fields aren't empty, process into database

} else {

	echo '<script>alert("Some fields were not filled out!");</script>';
	header("Location: http://www.inkzoid.com/shoutbox/shout.php");

	// if required fields were left empty, show an error dialog

}

}/* else {

echo '<script>alert("Please follow the form to this page.");</script>';
header("Location: http://www.inkzoid.com/shoutbox/shout.php");

// if they weren't even referred from the form, show error dialog and redirect

} // if isset post shout

/* STARTING THE MAIN SCRIPT NOW */

// starting the table

//displaying the shouts
getShouts();


mysql_close($l);


?>

Link to comment
Share on other sites

Firefox says when I click on gallery.php:

 

The page isn't redirecting properly

 

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

 

    *  This problem can sometimes be caused by disabling or refusing to accept

          cookies.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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