Page 1 of 1

Simple question about variables used inside html tags

Posted: Mon Dec 29, 2008 7:56 pm
by jtorral
I have done most of my coding using nothing but php and then echoing the html tags like so ..

echo "<p>HELLO WORLD</p>";

this is fine. But now I am using a tool that generates a lot of html and I would like to just include the tidbits of php within the code as follows:

html code
...
...
...
<?php insert some php code then close php tag ?>
...
...
...
more html code
...
...
done with html


My problem is that if I have a really big chunk of html code I may include a php tag near the top and declare a variable inside of that tag the close the tag. Then, later on in the html code I will insert another php tag, try to reference the variable declared in the earlier php tag above but the value is not retained. How can I keep the value and use it again ?

Thanks

Re: Simple question about variables used inside html tags

Posted: Mon Dec 29, 2008 8:19 pm
by requinix
jtorral wrote:How can I keep the value and use it again ?
It should be.

What is the code you have? (You can remove most of the HTML chunks since they shouldn't affect PHP.) Also, what PHP version? I seem to recall a bug similar to this.

Re: Simple question about variables used inside html tags

Posted: Mon Dec 29, 2008 8:36 pm
by jtorral
php version is 4.4

Re: Simple question about variables used inside html tags

Posted: Mon Dec 29, 2008 10:01 pm
by jtorral
All this oced was generated by a tool. I then stuck some php tags in there and they dont hod the variable.

config.php holds the variables and their vaues. I highlighted in bold the setion that does not keep the variable in memory.

Code: Select all

[b]<?php include_once('config.php')"; ?>[/b]
 
<div style="background-image:url(qmimages/center_tile.gif)"><table cellpadding=0 cellspacing=0 style="width:100%;"><tr><td><div style="font-size:1px;width:6px;height:34px;background-image:url(qmimages/left_cap.gif);"></div></td><td style="width:100%;">
<ul id="qm0" class="qmmc">
 
        <li><a href="index.php">HOME</a></li>
        <li><span class="qmdivider qmdividery" ></span></li>
        <li><a class="qmparent" href="JavaScript&#058;void(0);">ITEMS</a>
 
                <ul>
                <li><a href="newitem.php">Register a new item</a></li>
                <li>[b]<? echo "<a href='showitems.php?qtype=m&skey=$userid'>"; ?>[/b]List my items</a></li>
                <li><a href="showitems.php?qtype=s&skey=">List stolen items</a></li>
                </ul></li>
 
        <li><span class="qmdivider qmdividery" ></span></li>
        <li><a class="qmparent" href="javascript&#058;void(0)">TOOLS</a>
 
                <ul>
                <li>[b]<?php echo"<a href='usercp.php?uid=$userid'>"; ?>[/b]Control Panel</a></li>
                <li><a href="members.php">Member list</a></li>
                <li><a href="sendreport.php">Send Report</a></li>
                </ul></li>
 
        <li><span class="qmdivider qmdividery" ></span></li>
        <li><a class="qmparent" href="javascript&#058;void(0)">ANSWERS</a>
 
                <ul>
                <li><a href="faq.php">FAQ</a></li>
                <li><a href="privacy.php">Privacy</a></li>
                <li><a href="aboutus.php">About us</a></li>
                <li><a href="contactus.php">Contact us</a></li>
                <li><a href="contactus.php">Terms</a></li>
                </ul></li>
 
        <li><span class="qmdivider qmdividery" ></span></li>
        <li><a href="search.php">SEARCH</a></li>
        <li><span class="qmdivider qmdividery" ></span></li>
        <li><a href="logout.php">LOGOUT</a></li>
<li class="qmclear">&nbsp;</li></ul>
</td><td><div style="border-width:0px 0px 0px 1px;border-color:#aaaaaa;border-style:solid;font-size:1px;width:8px;height:31px;"></div><td style="padding:0px 5px 0px 0px;"><input type="text" style="font-family:arial;font-size:12px;width:100px;border-style:solid;border-width:1px;border-color:#ffffff;border-top-color:#aca899;border-left-color:#aca899;" value=""></td><td style="padding:0px 5px 0px 0px;font-family:arial;font-size:10px;color:#444444">SEARCH</td><td><div style="font-size:1px;width:6px;height:34px;background-image:url(qmimages/right_cap.gif);"></div></td></tr></table></div>
 
 
<!-- Create Menu Settings: (Menu ID, Is Vertical, Show Timer, Hide Timer, On Click (options: 'all' * 'all-always-open' * 'main' * 'lev2'), Right to Left, Horizontal Subs, Flush Left, Flush Top) -->
<script type="text/javascript">qm_create(0,false,0,500,false,false,false,false,false);</script>
 
 
 

Re: Simple question about variables used inside html tags

Posted: Mon Dec 29, 2008 10:05 pm
by omniuni
I read too quickly.

Re: Simple question about variables used inside html tags

Posted: Mon Dec 29, 2008 10:29 pm
by requinix
Fair enough :)

jtorral: you sure config.php is getting loaded? Remember that PHP has some weird logic when trying to include files. Turn on display_errors and see if you get any Undefined Variable notices.

Code: Select all

<?php ini_set("display_errors", 1);
include_once('config.php'); ?>

Re: Simple question about variables used inside html tags

Posted: Mon Dec 29, 2008 10:50 pm
by omniuni
Thank you, tasairis. I got confused with the single-quotes in the HTML. I possibly read too quickly and/or mixed up part of this post with another. Either way, I'm tired and I think I shall go to bed before I post anything else embarrassing. :banghead:

Oh, and I am still trying to figure out why I escaped, or rather, tried to escape, the slash. I had myself so mixed up I fired up my editor just to see. Here I am writing a CMS, and I can't remember what characters need to be escaped.

Wow. :crazy: