[SOLVED] including but not displaying?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

[SOLVED] including but not displaying?

Post by d3ad1ysp0rk »

I want to include variables from one page (to use on my whole site), and then display them places on each page, but when i call on the page with

Code: Select all

<?PHP include('vars.php'); ?>
it displays everything in the file..

example of whats in vars.php:

Code: Select all

<?PHP 
$form = <<<F
<form action="$PHP_SELF" method="post" name="myform">
<input type="text" name="user">UserName:<br>
<input type="text" name="pass">PassWord:<br>
</form>
F;
?>
and index.php says:

Code: Select all

<?PHP include('vars.php'); ?>
<html>
<body>
Hey!
</body>
</html>
it displays ALL of the vars file ($form = <<<F, etc..), and then the rest of the page..


How can i call on only the variables?

(i just realized i typed way too much for such a simple problem :P )
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

not sure what you mean. i did this and got the form in vars to pop up in index if that's what you mean :

vars.php

Code: Select all

<?php

function form()
{
	echo '<form action="$PHP_SELF" method="post" name="myform"><input type="text" name="user">UserName:<br><input type="text" name="pass">PassWord:<br></form>';
}
?>
index.php

Code: Select all

<?php
<?PHP include('vars.php');?>
<html> 
<body>
<?php>form();?>
Hey! 
</body> 
</html>

edit : otherwise, you just call the variables that are in the form just like you would if you had passed them from a form by $_POST['user']; etc...
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

well its not as much the form, as the html at all (i just that as an example)

ill show u my real file:

pagevars.php

Code: Select all

$logged_box = <<<LDB
<tr>
<td valign="top">YOu're LoggED in!</td>
</tr>
LDB;

$loginbox = <<<LB
<tr>
<td valign="top">User: </td>
<td valign="top">
<form action="http://www.gamegatextreme.com/login.php" name="login" method="post">
<input type="text" name="usr" size="14"></td>
</tr><tr>
<td valign="top">Pass: </td>
<td valign="top">
<input type="password" name="pwd" size="14"></td>
</tr><tr>
<td valign="top" colspan="2" align="center">
<input type="submit" class="submitbutton" name="submit" value="Login">
&nbsp;<input type="reset" class="submitbutton" name="reset" value="Reset"></form><br>
Not registered? <br>Sign up <a href="http://www.gamegatextreme.com/signup.php">here</a>!</td>
</tr>
LB;

$platformbox = <<<PB
<table width="150" cellspacing="0" cellpadding="0" border="0">
<tr height="17"><td width="150"></td></tr>
<tr height="130"><td width="150" valign="top">
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/gc.php">Gamecube</a><br>
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/ps2.php">Playstation 2</a><br>
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/xbox.php">Xbox</a><br>
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/pc.php">PC</a><br>
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/handhelds.php">Handhelds</a><br>
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/upcoming.php">Upcoming</a><br>
</td>
</tr>
<tr height="3"><td width="150"></td></tr>
</table>
PB;
index.php

Code: Select all

<?PHP include('incs/pagevars.php'); ?>
<html>
<head>
<title>GGX Template</TITLE>
<meta name="description" content="GamegateExtreme - Unlocking the Gate to eXtreme Gaming!">
<link rel="stylesheet" href="incs/style.css" type="text/css">
</HEAD>
<body>
ALL THE BODY CONTENT HERE
</body>
</html>


now on index.php, i want to be able to just say
<?PHP echo $loginbox; ?> and have it output the HTML in my pagevars.php file.. instead, it just dumps everything in the file on top of index.php

this is index.php when you view it (and click view source):

Code: Select all

$logged_box = <<<LDB
<tr>
<td valign="top">YOu're LoggED in!</td>
</tr>
LDB;

$loginbox = <<<LB
<tr>
<td valign="top">User: </td>
<td valign="top">
<form action="http://www.gamegatextreme.com/login.php" name="login" method="post">
<input type="text" name="usr" size="14"></td>
</tr><tr>
<td valign="top">Pass: </td>
<td valign="top">
<input type="password" name="pwd" size="14"></td>
</tr><tr>
<td valign="top" colspan="2" align="center">
<input type="submit" class="submitbutton" name="submit" value="Login">
&nbsp;<input type="reset" class="submitbutton" name="reset" value="Reset"></form><br>
Not registered? <br>Sign up <a href="http://www.gamegatextreme.com/signup.php">here</a>!</td>
</tr>
LB;

$platformbox = <<<PB
<table width="150" cellspacing="0" cellpadding="0" border="0">
<tr height="17"><td width="150"></td></tr>
<tr height="130"><td width="150" valign="top">
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/gc.php">Gamecube</a><br>
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/ps2.php">Playstation 2</a><br>
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/xbox.php">Xbox</a><br>
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/pc.php">PC</a><br>
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/handhelds.php">Handhelds</a><br>
&nbsp;- <a href="http://www.gamegatextreme.com/platforms/upcoming.php">Upcoming</a><br>
</td>
</tr>
<tr height="3"><td width="150"></td></tr>
</table>
PB;
<html>
<head>
<title>GGX Template</TITLE>
<meta name="description" content="GamegateExtreme - Unlocking the Gate to eXtreme Gaming!">
<link rel="stylesheet" href="incs/style.css" type="text/css">
</HEAD>
<body>
...
</body>
</html>

Thanks for your help.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

try this :

pagevars.php

Code: Select all

<?php
function login_box()
{
echo '<tr><td valign="top">YOu''re LoggED in!</td> 
</tr> 
<tr> 
	<td valign="top">User: </td> 
	<td valign="top"> 
		<form action="http://www.gamegatextreme.com/login.php" name="login" method="post"> 
		<input type="text" name="usr" size="14"></td> 
		</tr><tr> 
		<td valign="top">Pass: </td> 
		<td valign="top"> 
		<input type="password" name="pwd" size="14">
	</td> 
</tr>
<tr> 
	<td valign="top" colspan="2" align="center"> 
		<input type="submit" class="submitbutton" name="submit" value="Login"> 
		<input type="reset" class="submitbutton" name="reset" value="Reset"></form><br> 
			Not registered? <br>Sign up <a href="http://www.gamegatextreme.com/signup.php">here</a>!
	</td> 
</tr>';
}

function platformbox()
{
	echo '<table width="150" cellspacing="0" cellpadding="0" border="0"> 
	<tr height="17"><td width="150"></td></tr> 
	<tr height="130"><td width="150" valign="top"> 
	 - <a href="http://www.gamegatextreme.com/platforms/gc.php">Gamecube</a><br> 
	 - <a href="http://www.gamegatextreme.com/platforms/ps2.php">Playstation 2</a><br> 
	 - <a href="http://www.gamegatextreme.com/platforms/xbox.php">Xbox</a><br> 
	 - <a href="http://www.gamegatextreme.com/platforms/pc.php">PC</a><br> 
	 - <a href="http://www.gamegatextreme.com/platforms/handhelds.php">Handhelds</a><br> 
	 - <a href="http://www.gamegatextreme.com/platforms/upcoming.php">Upcoming</a><br> 
	</td> 
	</tr> 
	<tr height="3"><td width="150"></td></tr> 
	</table> ';
}
?>






index.php

Code: Select all

<?PHP include('inc/pagevars.php');?>
<html> 
<head> 
<title>GGX Template</TITLE> 
<meta name="description" content="GamegateExtreme - Unlocking the Gate to eXtreme Gaming!"> 
<link rel="stylesheet" href="incs/style.css" type="text/css"> 
</HEAD> 
<body> 
<? login_box() ?>
</body> 
</html>

edit : if you want to add platformbox in there, just put in another <?php platformbox() ?> after your login_box and it will put it in there too. hope that helps.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

omg.. i just realized why..

there was no <?PHP ?> tags in my pagevars.php file..wow i feel dumb :)

lol thanks for your help
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Yeah that is one of the lessons you learn once and never screw up on again. ;)

I would have pointed it out but I thought it was just the way the forum parsed your BBCode. =P
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

lol, same here, is why i kept posting those variations heh
Post Reply