Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

could you please tell what`s wrong with the end of this code and why it says: "Parse error: syntax error, unexpected end of file in php file":

<?php

define("DB_SERVER" , "localhost");
define("DB_USER" , "root");
define("DB_PASS" , "root");
define("DB_NAME" , "widget_corp");
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title> CMS MANAGEMENT </title>
    <link rel="stylesheet" type="text/css" href="stylesheets/style.css">
</head>
<body>
    <header>
    <h1> widget Corp <h1>
    </header>
<?php
require("constants.php");


// mysql connection
    $connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS);
    if (!$connection){
        die("Database Connection failed:". mysql_error());
    }

// select database
    $db_select = mysqli_select_db($connection , DB_NAME);
    if (!$db_select) {
        die("Database selection failed:" . mysql_error());
        }
    ?>
    <nav>
    <ul class="subject">
<?php 

    $subject_set = mysqli_query($connection, "SELECT * FROM subjects" );
    if (!$subject_set){
        die("mysql failed" . mysql_error());
    }
        while ($subject = mysql_fetch_array($subject_set)){
        echo "<li>{$subject["menu_name"]}</li>";
    }
        $page_set = mysqli_query($connection, "SELECT * FROM pages WHERE subject_id = {$subject["id"]}");
            if (!$page_set){
                die("Database query failed: " . mysql_error);


        echo "<ul class=\"pages\">";
        while ($page = mysqli_fetch_array($page_set)){
            echo "<li>{$page["menu_name"]}</li>";
    }
    echo "</ul>";


?>
    <?php echo "</ul>"; ?>

    </section>

    <?php mysqli_close($connection);?>
share|improve this question
    
Missing } after die("Database query failed: " . mysql_error); –  cOle2 Jul 14 at 14:44
    
You're missing a closing curly bracket for this block: if (!$page_set) { –  Robbert Jul 14 at 14:45

1 Answer 1

up vote 1 down vote accepted

EDIT

I've also updated the code a little for formatting and you were missing a </nav> tag. Also, there's no point in echoing out the </ul> tag if you're not in the middle of a php block.


You are missing a bracket }. I've added it after:

if (!$page_set){
                die("Database query failed: " . mysql_error);

<?php require_once("includes/functions.php"); ?>
<?php require_once("includes/constants.php"); ?>
<?php include("includes/header.php"); ?>
<?php include("includes/connection.php"); ?>
    <nav>
        <ul class="subject">
            <?php 
                $subject_set = mysqli_query($connection, "SELECT * FROM subjects" );
                if (!$subject_set){
                    die("mysql failed" . mysql_error());
                }

                while ($subject = mysql_fetch_array($subject_set)){
                    echo "<li>{$subject["menu_name"]}</li>";
                }

                $page_set = mysqli_query($connection, "SELECT * FROM pages WHERE subject_id = {$subject["id"]}");

                if (!$page_set){
                    die("Database query failed: " . mysql_error);
                }

                echo "<ul class=\"pages\">";
                while ($page = mysqli_fetch_array($page_set)){
                    echo "<li>{$page["menu_name"]}</li>";
                }
                echo "</ul>";
            ?>
        </ul>
    </nav>
</section>

<?php mysqli_close($connection);?>
share|improve this answer
    
thanks a lot @james cOle2 Robbert –  mphph Jul 14 at 14:56
    
No problem. If this answered your question though, don't forget to click the check mark to mark it answered. :) –  James Jul 14 at 15:14
    
sure, but I don`t know why, it was my first question in stackoverflow, and I also tried to vote the comments but it said I don`t have enough credit yet... –  mphph Jul 14 at 15:22
    
Do you mean you tried marking it as the answer and it wouldn't let you? I understand the voting, but am surprised at marking the answer. –  James Jul 14 at 15:29
    
I thought there is a button for this ! –  mphph Jul 14 at 16:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.