PHP Parse错误:语法错误,使用IF替代语法的意外文件结束

时间:2016-02-09 10:53:56

标签: php syntax compiler-errors

我似乎无法弄清楚这个PHP错误。我已经用“示例”替换了任何敏感信息,但我敢打赌这是我脸上的东西,我看不到它。

这是错误:

  

解析错误:语法错误,第272行/example.php中意外的文件结尾

<?php 
    session_start();
    // If you haven't entered a number, redirect back to index
    if (!$_SESSION['EXAMPLE'])
        die(header('Location: http://www.example.com/'));

    **//REMOVED THESE ON PURPOSE JUST FYI**
    $servername = "";
    $username = "";
    $password = "";
    $dbname = "";

    // Create Connection
    $con = new mysqli($servername, $username, $password, $dbname);

    // Check Connection
    if ($con->connect_error)
    {
        ("Connection failed: " . $con->connect_error);
    }

    // Search database for number
    $num = $_SESSION['exa'];
    $stmt = $con->prepare("SELECT * FROM numbers WHERE BINARY number = ?");
    $stmt->bind_param("s", $exa);

    $stmt->execute();
    /*$result = $stmt->get_result();
    $row = $result->fetch_assoc();*/

    // Get values out of response
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];
    $example = $result['EXAMPLE'];

    $con->close();
?>

<!DOCTYPE>
<html lang="en">

</head>
<body id="page-top" class="index">

    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-fixed-top">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header page-scroll">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#page-top">Dollar Reverse: Summary Reverse Results</a>

            <!-- Collect the nav links, forms, and other content for toggling
           <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
               <ul class="nav navbar-nav navbar-right">
                    <li class="hidden">
                        <a href="#page-top"></a>
                    </li>
                    <li class="page-scroll">
                        <a href="#portfolio"></a>
                    </li>
                    <li class="page-scroll">
                        <a href="#about"></a>
                    </li>
                    <li class="page-scroll">
                        <a href="#contact"></a>
                    </li>
                </ul>
            </div>
            /.navbar-collapse -->
        </div>
        </div>
        <!-- /.container-fluid -->
    </nav>


    <section id="portfolio">
        <div class="container">
            <div class="row">
                <div class="col-lg-12 text-center">
                    <h2>Reverse Lookup Information Located</h2>
                    EXAMPLE DATA:&nbsp; <?php echo $_SESSION['EXAMPLE'] ?>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4 text-capitalize text-center">
                    <?php

                    if ($_SESSION['EXAMPLE'] != NULL): ?>
                    <div class="portfolio-item">
                        <span class="glyphicon glyphicon-user"></span><br />
                        EXAMPLE
                        <br />
                    </div>
                    <?php
                     if ($_SESSION['EXAMPLE'] != NULL): ?>
                    <div class="portfolio-item">
                        <span class="glyphicon glyphicon-picture"></span><br />
                        EXAMPLE
                        <br />
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4 text-capitalize text-center">
                    <?php
                      if ($_SESSION['EXAMPLE'] != NULL):  ?>
                    <div id="portfolio-item">
                        <span class="glyphicon glyphicon-home"></span><br />
                        EXAMPLE<br />
                    </div>
                    <?php  if ($_SESSION['EXAMPLE1'] != NULL || $_SESSION['EXAMPLE2'] != NULL || $_SESSION['EXAMPLE'] != NULL): ?>
                    <div class="portfolio-item">
                        EXAMPLE<br />
                    </div>
                    <?php
                     if ($_SESSION['example'] != NULL && $_SESSION['example'] != NULL && $_SESSION['example'] != NULL && $_SESSION['example'] != NULL): ?>
                    <div class="portfolio-item">
                        <span class="glyphicon glyphicon-home"></span><br />
                        EXAMPLE
                        <br />
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4 text-capitalize text-center">
                    <?php
                     if ($_SESSION['EXAMPLE'] != NULL): ?>
                    <div class="portfolio-item">
                        <span class="glyphicon glyphicon-phone"></span><br />
                        EXAMPLE<br/>
                    </div>

                    <?php
                     if ($_SESSION['EXAMPLE'] != NULL): ?>
                    <div class="portfolio-item">
                        <span class="glyphicon glyphicon-text-background"></span><br />
                        EXAMPLE<br />
                    </div>

                    <?php
                     if ($_SESSION['EXAMPLE'] != NULL): ?>
                    <div class="portfolio-item">
                        <span class="glyphicon glyphicon-earphone"></span><br />
                        EXAMPLE<br>
                    </div>
                </div>
            </div>


<div style="text-align:center"> 
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="T35Q6SBDYT522">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</div>



    </div>

</section>
<footer>

</footer>

    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Plugin JavaScript -->
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
    <script src="js/classie.js"></script>
    <script src="js/cbpAnimatedHeader.js"></script>

    <!-- Contact Form JavaScript -->
    <script src="js/jqBootstrapValidation.js"></script>
    <script src="js/contact_me.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="js/freelancer.js"></script>

    <script src='js/jqmask.js'></script>
    <script src="js/main.js"></script>
</body>

</html>

1 个答案:

答案 0 :(得分:4)

<?php if ($_SESSION['EXAMPLE'] != NULL): ?>
<div class="portfolio-item">
    <span class="glyphicon glyphicon-user"></span><br />
    EXAMPLE
    <br />
</div>
<?php if ($_SESSION['EXAMPLE'] != NULL): ?>

您似乎缺少每个endif;(替代语法)结构的if ():语句。 (这也会产生嵌套这些if构造的不良影响。)

解析器在if ():构造关闭之前到达文件末尾,因此&#34;意外结束文件&#34;错误。

例如:

<?php if (isset($_SESSION['EXAMPLE'])): ?>
<div class="portfolio-item">
    <span class="glyphicon glyphicon-user"></span><br />
    EXAMPLE
    <br />
</div>
<?php endif; ?>
<?php if (isset($_SESSION['EXAMPLE'])): ?>

我还将不等式比较(!= NULL)更改为isset(),这意味着同样的事情(已设置且不为空)并且可能更容易阅读。而且重要的是,如果未设置变量,则不会触发E_NOTICE。

这可能只是一个例子,但如果你真的一个接一个地进行相同的比较,那么你也可以将它们组合成一个if ():结构。

除了:

if (!$_SESSION['EXAMPLE'])
    die(header('Location: http://www.example.com/'));

如果未设置$_SESSION['EXAMPLE'],则会触发E_NOTICE。最好先检查!isset()empty(),具体取决于它可能包含的值。例如:

if (empty($_SESSION['EXAMPLE']))
    // Error...

使用empty()更容易阅读,但请先检查这是否适合您的情况。变量被视为&#34;空&#34;如果它评估为 false (即&#34;&#34;,&#34; 0&#34;,0,false,null,未设置)。