3

I can't seem to figure out this PHP error. I've replaced any sensitive information with "example", but I would bet it's something staring me in the face and I don't see it.

Here is the error:

Parse error: syntax error, unexpected end of file in /example.php on line 272

<?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>
MrWhite
  • 43,179
  • 8
  • 60
  • 84

1 Answers1

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): ?>

You appear to be missing an endif; statement for each of your if (): (alternative syntax) constructs. (This will also have the undesired effect of nesting these if constructs.)

The parser is getting to the end of the file before the if (): construct is closed, hence the "unexpected end of file" error.

For example:

<?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'])): ?>

I've also changed the inequality comparison (!= NULL) with isset(), which means the same thing (is set and is not null) and is possibly easier to read. And importantly, will not trigger an E_NOTICE if the variable is not set.

This is perhaps just an example, but if you are literally making the same comparison one after the other then you might as well combine them into one if (): construct.


Aside:

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

This will trigger an E_NOTICE if $_SESSION['EXAMPLE'] is not set. You are better off checking !isset() or empty(), depending on the values it might contain. For example:

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

Using empty() is easier to read, but check first whether this is suitable in your case. A variable is considered "empty" if it evaluates to false (ie. "", "0", 0, false, null, not set).

MrWhite
  • 43,179
  • 8
  • 60
  • 84