Page 1 of 1

Parse error for SSI navigation menu images

Posted: Sat Dec 13, 2003 7:39 am
by CMS
I'm trying to create a navigation menu with 'on' and 'off' versions of buttons.

I've created a series of if/else/endif statements - example below

Code: Select all

<?php if (var="churches") then %><a href="churches.php"><img src="images/churches_on.gif" width="154" height="28" hspace="0" vspace="0" border="0" alt="Churches"></a><% else %><a href="churches.php"><img src="images/churches_off.gif" width="154" height="28" hspace="0" vspace="0" border="0" alt="Churches"></a><% end if

?>
and put the following line of code on the churches.php page:

Code: Select all

<?php
<? set var="page" value="churches" ?>
?>
When I access that page, I get this error:

Parse error: parse error, unexpected T_VAR in /home/content/c/m/s/cmsds/html/kouts/churches.php on line 1

This is my first attempt to do this and I haven't been able to find any tutorials about it as related to .php instead of .shtml files. Any help would be greatly appreciated!

Thanks.

Posted: Sat Dec 13, 2003 9:31 am
by uberpolak
Wow, code first, then something of an explanation.

Code: Select all

<?php

function onoff($p) {
    if ($p == 'churches') {
        return 'on';
    } else {
        return 'off';
    }
}

?>

<a href="churches.php"><img src="images/churches_<?php echo onoff($page); ?>.gif" width="154" height="28" hspace="0" vspace="0" border="0" alt="Churches"></a>

?>
The function checks to the value of whatever variable you give it, in this case, $page. If the value is "churches" it uses "on", otherwise "off". In the HTML section, it echoes the appropriate value.

Then on the churches.php page, put this:

Code: Select all

<?php
$page = 'churches';
?>
The reasons why your code didn't work:

Using <% ... %> to delimit code is an ASP thing. Some servers have it enabled for PHP, but it's usually best to use <?php ... ?>, since most don't.

In PHP, variables are denoted with a $, so use $page, not just page when you want to access that variable. I'm not too familiar with the VB style syntax (using endif and whatnot), so I can't say if that aspect of your code was correct, but I suspect it wasn't. Besides, its much easier to embed PHP in HTML, rather than vice versa.

The code to set a variable is just $var = 'value';
There is no need for a set command.

I suspect the reason you have <? after you already had <?php is accidental, due to the PHP button doing things automatically, but in case that wasn't it, I'll point it out anyway. Don't do that.

Perhaps you should read a basic PHP tutorial before getting into specifics.
http://www.php.net/tut.php is a good start.

Re: Parse error for SSI navigation menu images

Posted: Sat Dec 13, 2003 9:34 am
by Gen-ik

Code: Select all

<?php
if ($page=="churches") { ?>

<a href="churches.php">
<img src="images/churches_on.gif" width="154" height="28" hspace="0" vspace="0" border="0" alt="Churches"></a>

<?php } else { ?>

<a href="churches.php"><img src="images/churches_off.gif" width="154" height="28" hspace="0" vspace="0" border="0" alt="Churches"></a>

<?php } ?>

Code: Select all

<?php
$page="churches";
?>

Thanks!!

Posted: Tue Dec 23, 2003 6:04 am
by CMS
Works great. Thanks!!!!