Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mixing php and html within a script

Status
Not open for further replies.

tnsbuff

Technical User
Jan 23, 2002
216
US
Hi,

I know this is a simple question, but I'm new to this so please excuse my ignorance.

Here's my problem. I'm using a shopping cart script that's written in php. Within the admin area of the cart, you can specify the html for a custom header of the shop pages, which I've done.

What I want to do is insert php code in between the <title></title> tags so that the category name will be dynamically displayed, which isn't the way the script is written now. It just displays a static title for all pages.

The problem that I've run into is that this header code that's specified in the admin section is placed into a (string) variable for the script to access, so even though I've placed my code between the php script delimiters (within the title tags) it's displaying the code in the title bar instead of executing it. How do I correct this?

Thanks very much.

 
Does using this
<title>&quot; . $cat_name .&quot;</title>
or
<title>' . $cat_name .'</title>
in place of
<title><?= $cat_name ?></title>
work?

Rick -----------------------------------------------------------
 
Hi,

I tried both of your suggestions, but it's still displaying the code instead of executing. Any other suggestions? :)
 
Are you storing the title as a variable and then accessing it something like this?

<?= $total_title ?>

Because you could set that like this:
<? $total_title=&quot;<table>&quot; . $cat . &quot;</table>&quot;; ?>

If this doesn't work, please post code!

Rick -----------------------------------------------------------
 
I do think you're on the right track, though. It's obviously thinking the php code is part of the string that makes up the header variable. It seems like your suggestions should work, but for some reason they're not.
 
Sorry, I was posting just as you were.

Actually, what I have right now is just this:

<title>&quot;. $HTTP_GET_VARS[cat ].&quot;</title> (I had to put that space after cat, otherwise it's displaying a &quot;cat&quot;) ;-)

Once I get it to work, I need to do a little more coding to see if the category is even in the url. On some pages, it won't be so I need to display something else, but for now I'm just trying to get any code to work within that area.

Also, remember, I only have this custom header area to work with. The script is a pre-installed script from the hosting company, and they occasionally make updates to the script and replace it, so any customization other than what I can put in the custom header area is probably not a good idea, since it would be overwritten by any updates.

Thanks a bunch for your assistance.
 
I need to see where the title is displayed. Even if we can't edit it, I can see how it is implemented.

Rick -----------------------------------------------------------
 
I'm not following your suggestion about using this:

<? $total_title=&quot;<table>&quot; . $cat . &quot;</table>&quot;; ?>

even though I think you meant <title> instead of <table>
 
I did mean title :-D. That's why I need to see where the script is that outputs the title. I see where you set the title above, but I need to see where the doc writes out the title for me to see how to set it.

Rick -----------------------------------------------------------
 
Okay, there's an administrative area for the shopping cart. On the &quot;General Settings&quot; page, you can specify a custom header, so inside a textarea that it gives me to display my custom header code, I have this:

<html><head><title>&quot;. $HTTP_GET_VARS[cat].&quot;</title>

. . . plus the rest of the header html which includes logo, etc.

When I submit this, the header html (and my php code) is inserted into a variable called $header (or something like that), which is then used by the script to display my custom header on every page of the shop.

Does that make sense?

 
That darn cat!

Do you need the function in the script that displays the header?
 
Yes I need the function that displays the header. I'm going to bed now, so either I'll try to answer in the morning, or maybe someone else will see this before then.

Rick -----------------------------------------------------------
 
Okay, this is very long, but it also contains the code for the header if a custom header has not been defined. I wasn't sure exactly which part you needed so I included it all, although I think what might be the applicable part is in bold:

-----------------------------------------------------------

# shows header (inc. custom layout for shop
function showhead($shop,$cat,$cart,$titleadd = &quot;&quot;) {

$ret = &quot;<!-- START HEADER -->\n&quot;;

$shopid = intval($shop);
$qry_gethead = mysql_query(&quot;SELECT name, title, dividercellcolor, pagetitle, shoplogo, background, fontcolour, fontfamily, &quot;.
&quot;fontsize, linkcolour, visitedlinkcolour, activelinkcolour, header, &quot;.
&quot;displaycartlink, displayhomelink, otherhomelink, displaysearchbox &quot;.
&quot;FROM shop &quot;.
&quot;WHERE id=$shop&quot;);
list ($name,$title,$dividercellcolor,$pagetitle,$shoplogo,$background,$fontcolour,$fontfamily,$fontsize,$linkcolour,$visitedlinkcolour,$activelinkcolour,$header,$displaycartlink, $displayhomelink, $otherhomelink, $displaysearchbox) = mysql_fetch_array($qry_gethead);

if (trim($header) != '' && $titleadd != '| Final Page') {
// if theyve created a custom header...
$ret .= $header . &quot;\n<!-- STOP HEADER -->&quot;;
return $ret;
}

$ret .= &quot;<html>\n<head>\n&quot;;
$ret .= &quot; <title>$name - $title $titleadd</title>\n&quot;;
$ret .= &quot; <style type='text/css'>\n&quot;;
$ret .= &quot; body {\n&quot;;
if (ereg(&quot;^#&quot;,$background)) {
$ret .= &quot; background-color: $background;\n&quot;;
}
else {
$ret .= &quot; background-image: url($background);\n&quot;;
}
$ret .= &quot; color: $fontcolour;\n&quot;;
$ret .= &quot; font-family: $fontfamily;\n&quot;;
$ret .= &quot; font-size: &quot;.$fontsize.&quot;px;\n&quot;;
$ret .= &quot; }\n&quot;;

$ret .= &quot; td {\n&quot;;
$ret .= &quot; color: $fontcolour;\n&quot;;
$ret .= &quot; font-family: $fontfamily;\n&quot;;
$ret .= &quot; font-size: &quot;.$fontsize.&quot;px;\n&quot;;
$ret .= &quot; }\n&quot;;

$ret .= &quot; input {\n&quot;;
$ret .= &quot; font-family: $fontfamily;\n&quot;;
$ret .= &quot; font-size: &quot;.$fontsize.&quot;px;\n&quot;;
$ret .= &quot; }\n&quot;;

$ret .= &quot; textarea {\n&quot;;
$ret .= &quot; font-family: $fontfamily;\n&quot;;
$ret .= &quot; font-size: &quot;.$fontsize.&quot;px;\n&quot;;
$ret .= &quot; }\n&quot;;

$ret .= &quot; select {\n&quot;;
$ret .= &quot; font-family: $fontfamily;\n&quot;;
$ret .= &quot; font-size: &quot;.$fontsize.&quot;px;\n&quot;;
$ret .= &quot; }\n&quot;;
$ret .= &quot; .justified {\n&quot;;
$ret .= &quot; text-align: justify;\n&quot;;
$ret .= &quot; }\n&quot;;

$ret .= &quot; </style>\n&quot;;
$ret .= &quot;</head>\n&quot;;

$ret .= &quot;<body link='$linkcolour' vlink='$visitedlinkcolour' alink='$activelinkcolour'>&quot;;

$ret .= &quot;<table border=0 width='100%' cellpadding=0 cellspacing=0>&quot;;
$ret .= &quot;<tr>&quot;;
$ret .= &quot;<td width=50% valign=top>&quot;;

//$qry_getpagetitle = mysql_query(&quot;SELECT pagetitle FROM shop WHERE id=$shop&quot;);
//list ($pagetitle) = mysql_fetch_array($qry_getpagetitle);
if ($shoplogo != '' and $titleadd != '| Final Page') {
$ret .= &quot;<a href='index.php?shop=$shop&cart=$cart'><img src='$shoplogo' border=0 alt='$title'></a>&quot;;
} else {
$ret .= &quot;<font size=4><b>$title</b></font>&quot;;
}
$ret .= &quot;</td>&quot;;
$ret .= &quot;<td height=60 width=50% valign=top align=right>&quot;;
if ($displaysearchbox == 1)
$ret .= &quot;<form method=GET action='&quot; . URL_START . &quot;index.php'>Search Inventory for Keyword(s):<br><input type=text name=keywords value='' size=21 maxlength=50><input type=submit value='Search'><input type=hidden name=shop value='$shop'><input type=hidden name=cart value='$cart'></form>&quot;;
else
$ret .= &quot; &quot;;
$ret .= &quot;</td>&quot;;
$ret .= &quot;</tr>&quot;;
$ret .= &quot;<tr>&quot;;
$ret .= &quot;<td valign=middle>$pagetitle</td>&quot;;




// Begin - Custom Display Arrangement - 03042002
$tcartlink = &quot;&quot;;
if ($displaycartlink == 1) {
if ($titleadd != '| Final Page') {
$tcartlink = &quot;<a href='cart.php?shop=$shop&cart=$cart'>View Shopping Cart</a>&quot;;
} else {
$tcartlink = &quot;<a href='&quot; . URL_START . &quot;cart.php?shop=$shop&cart=$cart'>View Shopping Cart</a>&quot;;
}
}

$thomelink = &quot;&quot;;
if ($displayhomelink == 1) {
if ($titleadd != '| Final Page') {
$thomelink = &quot;<a href='index.php?shop=$shop&cart=$cart'>Home</a>&quot;;
} else {
$thomelink = &quot;<a href='&quot; . URL_START . &quot;index.php?shop=$shop&cart=$cart'>Home</a>&quot;;
}
}
elseif ($displayhomelink == 2)
$thomelink = &quot;<a href='$otherhomelink'>Home</a>&quot;;
if ($tcartlink == &quot;&quot; && $thomelink == &quot;&quot;)
$tdisplay = &quot; &quot;;
elseif ($tcartlink == &quot;&quot;)
$tdisplay = $thomelink . &quot; &quot;;
elseif ($thomelink == &quot;&quot;)
$tdisplay = $tcartlink . &quot; &quot;;
else
$tdisplay = &quot;<a href=\&quot;previous_orders.php?shop=$shop&cart=$cart\&quot;>Order History</a> | &quot;.$tcartlink . &quot;  |  &quot; . $thomelink . &quot; &quot;;
$ret .= &quot;<td valign=middle align=right>&quot;.$tdisplay.&quot;</td>&quot;;
// End - Custom Display Arrangement
$ret .= &quot;</tr>&quot;;
$ret .= &quot;<tr>&quot;;
$ret .= &quot;<td colspan=2> </td>&quot;;
$ret .= &quot;</tr>&quot;;
$ret .= &quot;<tr>&quot;;
$ret .= &quot;<td colspan=2 bgcolor='$dividercellcolor'> </td>&quot;;
$ret .= &quot;</tr>&quot;;
$ret .= &quot;</table>&quot;;

$ret .= &quot;\n<!-- STOP HEADER -->&quot;;
return $ret;

}
 
Oh--I might have misunderstood. Is it outputting <title>...</title> into the title? If that's the problem, it is because the <title> tags are added below, a line or two after the bold ones above.

What variable holds the <html><head><title>&quot;. $HTTP_GET_VARS[ c a t ].&quot;</title> ? Are you hard-coding that line into the page, or are you entering it into a textbox type thing and it inserts it automatically? Because if you are doing the latter, I think that PHP is automatically backslashing the &quot;s so that it won't execute that as a script.

Rick -----------------------------------------------------------
 
Hi,

>>Is it outputting <title>...</title> into the title? <<

No, it's not outputting that. It's just outputting my php code (which I placed between the <title></title> tags.

>>If that's the problem, it is because the <title> tags are added below, a line or two after the bold ones above.
<<

No, that's not the problem. The lines that you mention that are in the code below the bold part are the code for a standard header if a custom header has not been defined.


>>What variable holds the <html><head><title>&quot;. $HTTP_GET_VARS[ c a t ].&quot;</title> ? <<

I'm assuming it's $header judging by the code above. (A custom header that is.)

The entire custom header code (which includes everything from <html><head><title>, etc. all the way down to where the product info starts is defined in a <textarea> box on the general settings page of the admin section.

>>Are you hard-coding that line into the page, or are you entering it into a textbox type thing and it inserts it automatically?<<

Entering it into a textarea as mentioned in previous paragraph, which is then inserted automatically, so that is obviously the problem.

Maybe there's no way to do what I want then?

Thanks for your time. I appreciate it!
 
No way that I can think of, except to find the value in the database and take out the slashes. Or you can edit their code and just remember to fit it when you update.
try checking &quot;title&quot; in the db and see if you can take out the slashes.

Rick -----------------------------------------------------------
 

RISTMO,

I haven't been able to find where the value of $header is stored. This script has tons of files, and so far I haven't found the one that stores that variable.

Anyway, thanks for all of your time. I really do appreciate it!
 
have u checked that PHP actually works? make a phpinfo.php in the root of your webserver and add the following:
<? phpinfo(); ?>

If you see nothing, then PHP isn't working, if you see a whole load of info, then its working.

As for your title problem:
<title><?=&quot;string&quot; ?></title>
or:
<title><?=$variable ?></title>

Wrong:
<title>&quot;.$variable.&quot;</title>
unless of course it is:
echo &quot;<title>&quot;.$variable.&quot;</title>&quot;; --BB
 
>>Have u checked that PHP actually works?<<

Yes, it works fine. The shopping cart script is working perfectly, and it's written in php. It's just that I can't get that piece of code to execute, but I'm quite sure it's because, like RISTMO said, the script is adding slashes to the text inside the variable that holds $header. (It's not expecting any php to be in that string.)

Thanks for the suggestion though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top