PHP - 意外的T_ELSE

时间:2014-04-08 19:19:53

标签: php

早上好,这是我第一次,我请你帮忙。是的,我使用了搜索按钮。我有这个问题:解析错误:语法错误,第80行的quest2.php中出现意外的T_ELSE。还有一个else语句。对不起,如果事实证明我失明了。这是quest2.php代码

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="http://jquery-countdown.googlecode.com/svn/trunk/js/jquery.countdown.js"></script>
<style type="text/css">
      br { clear: both; }
      .cntSeparator {
        font-size: 54px;
        margin: 10px 7px;
        color: #000;
      }
      .desc { margin: 7px 3px; }
      .desc div {
        float: left;
        font-family: Arial;
        width: 70px;
        margin-right: 65px;
        font-size: 13px;
        font-weight: bold;
        color: #000;
      }
    </style>

<?php 
require 'core.inc.php';
require 'connection.inc.php';
if(loggedin())
 {  
 $rightvar=$_SESSION['user_id'];
 $result = mysql_query("SELECT * FROM users WHERE id = $rightvar") or die(mysql_error());  
               $data = mysql_fetch_array($result);  
   $username=$data['username'];
   $coins=$data['coins'];
   $userid=$data['id'];
$banned=$data['banned'];
    $queststart = date('Y-m-d H:i:s', strtotime("+0 minutes"));
$coinsget = rand(10, 100);
$questactive=$data['questActive'];
$questtime=$data['questTime'];
$date = new DateTime('now');
$remaintime = date('i:s', strtotime($questtime) - strtotime($queststart));
$zamereni=$data['Zamereni'];
$edit = $data['editActive'];
$actualviews=$data['totalViews'];
$viewsgetfromdb=$data['viewsGet'];
$subsfromdb=$data['questReward'];
$actualsubs=$data['coins'];
$finalsubs = $subsfromdb + $actualsubs;
$finalview = $actualviews + $viewsgetfromdb;
echo '<script type="text/javascript">';
echo "    $('#counter').countdown({";
echo "    image: 'http://jquery-countdown.googlecode.com/svn/trunk/img/digits.png',";
echo "    startTime: '" . $remaintime . "', ";
echo "    timerEnd: function(){ window.open('here I have the relevant path to quest2.php'," . '"_self"' . "); }, ";
echo "    format: 'mm:ss'";
echo "  });";
echo "});";
echo "</script>";
if($questactive == 0)
{
echo '<meta http-equiv="refresh" content="0;url=quest.php">Loading...';
}
else
{
echo 'Video bude/bylo natoceno: ' . $questtime . '<br>';
}
if(strtotime($queststart) > strtotime($questtime))
{
echo '<title>' . 'Dokonceno' . ' - Nataceni videa - MyTube Simulator</title>Uz mas hotovo ' . '<br>';
if($edit == 1)
{
echo '<meta http-equiv="refresh" content="0;url=edit2.php">Loading...';
}
if($zamereni == 1)
{
echo 'Prejes si sve video vyeditovat? <a href="chcieditovattodlenctomojevideo.php">Ano</a> nebo <a href="nechciniceditovatjsemliny.php">Ne</a>';
}
    else
    {
    echo '<a href="upload.php">Mate hotovo - nahrat</a>';
    }
    else //this is the else where the error happens
    {
    echo 'Hotovo nemas<br>';
    echo '<title>Nataceni videa - MyTube Simulator</title>Zbyva <div id="counter_2"></div><div class="desc"><div>Minut</div><div>Sekund</div></div>';
    }
    else
    {
    echo '<a href="register">Register</a> or <a href="login.php">login</a>';
    }
    ?>

那么,你能帮助我吗?这是发生错误的部分

if($questactive == 0)
{
echo '<meta http-equiv="refresh" content="0;url=quest.php">Loading...';
}
else
{
echo 'Video bude/bylo natoceno: ' . $questtime . '<br>';
}
if(strtotime($queststart) > strtotime($questtime))
{
echo '<title>' . 'Dokonceno' . ' - Nataceni videa - MyTube Simulator</title>Uz mas hotovo ' . '<br>';
if($edit == 1)
{
echo '<meta http-equiv="refresh" content="0;url=edit2.php">Loading...';
}
if($zamereni == 1)
{
echo 'Prejes si sve video vyeditovat? <a href="chcieditovattodlenctomojevideo.php">Ano</a> nebo <a href="nechciniceditovatjsemliny.php">Ne</a>';
}
else
{
echo '<a href="upload.php">Mate hotovo - nahrat</a>';
}
else //this is the else where the error happens
{
echo 'Hotovo nemas<br>';
echo '<title>Nataceni videa - MyTube Simulator</title>Zbyva <div id="counter_2"></div><div class="desc"><div>Minut</div><div>Sekund</div></div>';
}
else
{
echo '<a href="register">Register</a> or <a href="login.php">login</a>';
}

在尝试实现jQuery之前,我还必须注意代码工作正常 我实际上错过了那里的括号......两个括号,代码现在正在工作

1 个答案:

答案 0 :(得分:2)

你不能有多个else语句,而是使用elseif

请参阅PHP.net关于else statements的文档。

if($zamereni == 1)
{
echo 'Prejes si sve video vyeditovat? <a href="chcieditovattodlenctomojevideo.php">Ano</a> nebo <a href="nechciniceditovatjsemliny.php">Ne</a>';
}
else
{
echo '<a href="upload.php">Mate hotovo - nahrat</a>';
}
else //this is the else where the error happens
{
echo 'Hotovo nemas<br>';
echo '<title>Nataceni videa - MyTube Simulator</title>Zbyva <div id="counter_2"></div><div class="desc"><div>Minut</div><div>Sekund</div></div>';
}
else
{
echo '<a href="register">Register</a> or <a href="login.php">login</a>';
}

这就是问题所在。 if / else语句是boolean。如果表达式为true,则执行if语句,如果表达式为false,则执行else语句。没有其他可能性。