Page 1 of 1

Parse error: syntax error, unexpected T_IF in......

Posted: Thu Nov 08, 2007 3:07 pm
by wesb
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am having trouble with this error, i don't know how to fix it. here is the full error:
Parse error: syntax error, unexpected T_IF in /home/wesley/public_html/forums/header.php on line 15

I am quite new to php so i dunno if this is correct. Help would be much apreciated.
here is the code from the begining:

Code: Select all

<?php
require("config.php");
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
function curPageName()
{
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
?>
<ul class='leveltab'>
<li><a href='index.php'<?php if(curPageName('index.php')){echo "class='current'";}?>>Main Page</a></li>
<?php
if(isset($_SESSION['USERNAME']) == TRUE)
{
echo "<li><a href='logout.php'".if(curPageName('logout.php')){echo "class='current'";}.">Logout</a></li>";
}
else{
echo "<li><a href='login.php'>Login</a></li>";
echo "<li><a href='register.php'>Register</a></li>";
}
?>
<li><a href="newtopic.php">New Topic</a></li>
</ul>
now the first if statement works on the index part of the list becasue it has the php around it, but i need to know how to put this into the echo tag. cheers


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Nov 08, 2007 3:12 pm
by seppo0010
You can't concatenate with an if in the middle... Try using a short if

Code: Select all

<?php
if(isset($_SESSION['USERNAME']) == TRUE)
{
echo "<li><a href='logout.php'". (curPageName('logout.php') ? "class='current'" : "") .">Logout</a></li>";
}
else{
echo "<li><a href='login.php'>Login</a></li>";
echo "<li><a href='register.php'>Register</a></li>";
}
?>

Posted: Thu Nov 08, 2007 3:12 pm
by seppo0010
You can't concatenate with an if in the middle... Try using a short if

Code: Select all

<?php
if(isset($_SESSION['USERNAME']) == TRUE)
{
echo "<li><a href='logout.php'". (curPageName('logout.php') ? "class='current'" : "") .">Logout</a></li>";
}
else{
echo "<li><a href='login.php'>Login</a></li>";
echo "<li><a href='register.php'>Register</a></li>";
}
?>

Posted: Thu Nov 08, 2007 3:34 pm
by wesb
Thankyou for the fast reply, yes this has sort of sovled my problem i no longer get an error, but i would like the if statement to work so that if the current page name is false then the class is not included or has just disapeared. So like i have the site tab but i only want the current page to have the 'current' class. I dunno how to do this as i have never come accross that way of using an if function before. cheers

Posted: Thu Nov 08, 2007 3:42 pm
by seppo0010
I´m not sure I´m getting you... the if statement is working as you write it, but with a different shorter-sintaxis... did you try it when it´s true or false and didn´t work?

Posted: Thu Nov 08, 2007 3:47 pm
by wesb
it seems like its coming out true no matter what, which is a bit strange.