Jump to content

[SOLVED] Using Variables in include()


churdaddy

Recommended Posts

Could someone help this newb?

 

I am trying to setup a file system that pulls from teh querystring and then includes a page of links in my existing webpage.

 

			<?PHP
		$PartNum = $_GET['Part'];
		$PartPath = "../Parts/" .$PartNum. "/index.php";
		include($PartPath);
              ?>

 

Ive changed this a dozen times in different ways. The way it is now at least it doesn't keep the whole page from showing, but nothing in my Index php I'm trying to include shows up in the page. If I simply do

 

<?PHP
include("../Parts/113507/index.php");
?>

 

It works perfectly, but I want this data to change with the Querystring.

 

Thanks in advance.

Link to comment
Share on other sites

Tried both

 

echo $PartNum;

 

Does return the part number exactly correct.

 

 

<?php

  $PartNum=$_GET['Part'];

  $PartPath="../Parts/" .$PartNum. "/index.php";

  $codeline='include('.$PartPath.');';

  eval($codeline);

?>

 

Acted exactly as the old code. The index.php was not displayed in the page.

 

 

Link to comment
Share on other sites

Alright this is huge though. The Embed statement works perfectly.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">

<!-- #BeginTemplate "../master.dwt" -->

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- #BeginEditable "doctitle" -->
<title>Links</title>
<!-- #EndEditable -->
<link rel="stylesheet" title="CSS" type="text/css" href="../styles/style2.css" media="screen" />
<style type="text/css">
.style1 {
text-align: center;
}
.style2 {
margin-left: 41;
}
.style3 {
text-decoration: underline;
}
</style>
</head>

<body>

<!-- Begin Container -->
<div id="container" style="width: 959px; height: 794px">
<!-- Begin Masthead -->
<div id="masthead">
	<h1 class="style1">
	<img alt="Electritek" src="../images/LogoETI.gif" width="251" height="40" /><img alt="AVT" src="../images/LogoAVT.gif" width="125" height="40" /></h1>
	<h3><a href="http://www.electritek.com">www.electritek.com</a></h3>
</div>
<!-- End Masthead -->
<!-- Begin Navigation -->
<div id="navigation">
	<ul>
		<li><a href="../default.htm">Home</a></li>
		<li><a href="../about_me/about_me.htm">Links</a></li>
		<li><a href="../photo_gallery/photo_gallery.htm">Photo Gallery</a></li>
		<li><a href="PartInfo.php?Doc=ETI_Line_Card.pdf">Documents</a></li>
		<li><a href="../contact/contact.htm">Contact</a></li>
	</ul>
</div>
<!-- End Navigation -->
<!-- Begin content_container -->
<div id="content_container">
	<!-- Begin Left Column -->
	<div id="column_left" style="width: 530px">
		<!-- #BeginEditable "content" -->
		<embed width="530" src="../Parts/<?PHP echo $_GET['Part']?>/<?PHP echo $_GET['Doc']?>" style="height: 606px">
		<!-- #EndEditable --></div>
	<!-- End Left Column -->
	<!-- Begin Right Column -->
	<div id="column_right" class="style2" style="width: 212px; height: 597px">
		<!-- #BeginEditable "sidebar" -->
		<?php

$root = "..";
$PartNum = $_GET['Part'];
include ("{$path}/Parts/{$PartNum}/index.php");
echo $PartNum;
?>
              
              Yadda Yadda Yadda
		<!-- #EndEditable --></div>
	<!-- End Right Column -->
	<!-- Begin Footer -->
	<div id="footer">
		<div id="copyright">
			<p>Copyright © 0000. All Rights Reserved.</p>
		</div>
		<p><a href="../default.htm">Home</a> | <span class="style3"><strong>
		<a href="../about_me/about_me.htm">Links </a></strong></span>| 
		<a href="../photo_gallery/photo_gallery.htm">Photo Gallery</a> |<a href="PartInfo.php?Doc=ETI_Line_Card.pdf"">Documents</a>| 
		<a href="../contact/contact.htm">
		Contact</a></p>
	</div>
	<!-- End Footer --></div>
<!-- End content_container --></div>
<!-- End Container -->

</body>

<!-- #EndTemplate -->

</html>

 

The Part number and Yadda Yadda Yadda both show fine.

 

The index.php is here.

<h1>Documents</h1>
<BR />
<a href="PartInfo.php?Part=<?PHP echo $_GET['Part']?>&Doc=AVT_ETI_Line_Card.pdf">Doc One</a>
<BR />
<h1> Sub Assemblys - Parts </h1>
<BR />
<a href="PartInfo.php?Part=<?PHP echo $_GET['Part']?>&Doc=Start.pdf">Start</a>

Link to comment
Share on other sites

I reworked this quite a bit for debugging.

 

<?php
  $PartNum=$_GET['Part'];
  $PartPath="../Parts/" .$PartNum. "/index.php";
  $codeline='include($PartPath);';
  eval($codeline);
  include($PartPath);
echo $codeline;
echo '<br>';
echo $PartPath;
echo '<br>';
echo $PartNum;
echo '<br>';
?>

 

This returns

 

include($PartPath);

../Parts/AVT-900-112/index.php

AVT-900-112

 

On the page.

 

I think this proves that all the variables are working correctly. So two questions: Is it even possible to have a variable in the include line? If so what is going wrong? Thanks again everyone for working on this.

Link to comment
Share on other sites

Alright the file exist--

 

More internal Information

 

http://192.168.1.4/PartInfo/PartInfo.php?Part=AVT-900-112&Doc=Start.pdf

Is what I use to get to the whole page

 

http://192.168.1.4/Parts/AVT-900-112/index.php directly in the address of IE

Brings up the navigation bar I'm trying to create as a page and it shows its links fine.

 

the wierd thing is that this code stops processing 

require('../Parts/AVT-900-112/index.php');

 

I was wrong in my previous post today I have been unable to make this work either .

include('../Parts/AVT-900-112/index.php');

 

I guess one more question Parts is a virtual directory in IIS. do I need with PHP to make the include point to the actual folder on the system or is just pointing to the folder through the IIS path good enough?

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.