此PHP上的语法错误

此PHP上的语法错误,php,syntax,Php,Syntax,这段代码在带有“else”的行上为我提供了一个语法错误。任何建议,谢谢 <?php if($_SESSION['id']) echo '<div id="center" class="column">'; include("center.php"); echo'</div> <div id="left" class="column">'; include("leftbar.php"); echo'</div> <div id="righ

这段代码在带有“else”的行上为我提供了一个语法错误。任何建议,谢谢

<?php
if($_SESSION['id'])
echo '<div id="center" class="column">';
include("center.php");
echo'</div>
<div id="left" class="column">';
include("leftbar.php");
echo'</div>
<div id="right" class="column">';
include("rightbar.php");
echo '</div>';
else
echo '<h1>Staff please, <a href="index.php">login</a> 
before accessing this page, no access to students.</h1>';
?>

您需要将它们放在块中。块以
{
开始,以
}
结束

if($_SESSION['id']) {
  echo '<div id="center" class="column">';
  include("center.php");
  echo'</div>
  <div id="left" class="column">';
  include("leftbar.php");
  echo'</div>
  <div id="right" class="column">';
  include("rightbar.php");
  echo '</div>';
}
else {
  echo '<h1>Staff please, <a href="index.php">login</a> 
  before accessing this page, no access to students.</h1>';
}

是的,我的建议是使用括号。现在,您的代码基本上如下所示:

<?php
if($_SESSION['id']) {
    echo '<div id="center" class="column">';
}
include("center.php");
echo'</div>
<div id="left" class="column">';
include("leftbar.php");
echo'</div>
<div id="right" class="column">';
include("rightbar.php");
echo '</div>';
} else {} <--- error is here because there is no open if statement since you didn't use brackets
echo '<h1>Staff please, <a href="index.php">login</a> 
before accessing this page, no access to students.</h1>';
?>
<?php
if($_SESSION['id']) {
    echo '<div id="center" class="column">';
    include("center.php");
    echo'</div><div id="left" class="column">';
    include("leftbar.php");
    echo'</div><div id="right" class="column">';
    include("rightbar.php");
    echo '</div>';
} else {
    echo '<h1>Staff please, <a href="index.php">login</a> before accessing this page, no access to students.</h1>';
}
?>

你的键盘缺少括号吗?
{
}
?因为您的代码确实如此。非常感谢,这是web编程的新手:)
<?php
if($_SESSION['id']) {
    echo '<div id="center" class="column">';
    include("center.php");
    echo'</div><div id="left" class="column">';
    include("leftbar.php");
    echo'</div><div id="right" class="column">';
    include("rightbar.php");
    echo '</div>';
} else {
    echo '<h1>Staff please, <a href="index.php">login</a> before accessing this page, no access to students.</h1>';
}
?>