douzhong5902 2011-05-23 02:00
浏览 60
已采纳

在嵌套if块[关闭]中排除“解析错误:语法错误,意外T_ELSE”故障

I have the following code on my website:

<?php
$loggedout = $_GET["loggedout"];
if ($loggedout=="true") { 
echo '<body class="slider-header" onload="Modalbox.show(\'/data/loggedout\',{width: 576, title: \'Logged Out\'}); return false;">'; else { 
if (isset($_COOKIE["hide"]))
  echo '<body class="slider-header">';
else
  echo '<body class="slider-header" onload="Modalbox.show(\'/data/surveyinvite\',{width: 576, title: \'Website Survey\'}); return false;">';
}; ?>

What this should do is determine if $loggedout equals true and, if so, display /data/loggedout. If $loggedout is not true (or not present), it should then go on to determine if the cookie hide exists. If the cookie does exist, there should be no onload and if the cookie does not exist, it should display /data/surveyinvite.

However, I get the following error when going to my page:

Parse error: syntax error, unexpected T_ELSE in /home/briefs/public_html/index.php on line 16

Line 16 is

echo '<body class="slider-header" onload="Modalbox.show(\'/data/loggedout\',{width: 576, title: \'Logged Out\'}); return false;">'; else { 

I have determined that issue is somewhere in the following (if I get rid of it, $loggedout works as expected):

if (isset($_COOKIE["hide"]))
  echo '<body class="slider-header">';
else
  echo '<body class="slider-header" onload="Modalbox.show(\'/data/surveyinvite\',{width: 576, title: \'Website Survey\'}); return false;">';
}; 

Where is the issue in this code?

  • 写回答

2条回答 默认 最新

  • dsjklb0205 2011-05-23 02:06
    关注

    If you indent your code properly and always use brackets (I know they're not required; do it anyway, because it prevents stupid mistakes like this) then you'll find it much easier to not make such a simple mistake. You were missing several curly brackets, that's all.

    <?php
    $loggedout = $_GET["loggedout"];
    if ($loggedout=="true") { 
        echo '<body class="slider-header" onload="Modalbox.show(\'/data/loggedout\',{width: 576, title: \'Logged Out\'}); return false;">'; 
    } else { 
        if (isset($_COOKIE["hide"])) {
            echo '<body class="slider-header">';
        } else {
            echo '<body class="slider-header" onload="Modalbox.show(\'/data/surveyinvite\',{width: 576, title: \'Website Survey\'}); return false;">';
        }
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法