SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with include and { } in different files

    Hi there,

    I am getting a error in the final line of the first 'included' file below and I think it is because I am not closing a statement using the } symbol until in another file (later included).

    I am using this coding and the content looks fine in Dreamweaver but not when it is online:

    PHP Code:
    <?php include("coding.php"); ?>

    <?php include("top-navigation.php"); ?>

    <?php include("left-navigation.php"); ?>

    <?php include("product-content.php"); ?>

    <?php include("foot-navigation.php"); ?>
    I have an idea what the problem is. If you look at the coding for coding.php below you will see that I am not closing with the } in the coding.php file. Instead I am closing in a different php file. This is why I get an error. Like I say it works fine in Dreamweaver but not online. Is it because I am not closing with the } symbols? Does Internet Explorer not like closing in other files?!?


    PHP Code:
    <?php include("db.php");
    $result mysql_query("select * from cart inner join products on cart.productid = products.productid where cart.cookieid = '" GetCartId() . "' order by products.name asc");

    $res mysql_query("SELECT * FROM categories");
    while(
    $row mysql_fetch_array($res)) {
      
    $cats[$row['categoryid']] = $row['categoryname'];
    }
    //Load categories and products for category clicked.
    if(isset($_GET['category'])) {
     
    $selcat $_GET['category'];
    }
    //Load categories and products within category of product clicked.
    if(isset($_GET['product'])) {
    echo 
    "yes";
     
    $prod_info mysql_fetch_array(mysql_query("SELECT * FROM products WHERE productid = '".$_GET['product']."'"));
     
    //Prod_Info now gets stored for use in the main display.
     
    $selcat $prod_info['categoryid'];
     echo 
    $selcat;
    }
    $data mysql_query("SELECT * FROM products WHERE productid = '".$_GET['product']."'");
    while(
    $row mysql_fetch_array($data)){

    ?>
    Hope you can help,

    Matt.

  2. #2
    SitePoint Member
    Join Date
    Nov 2011
    Location
    Madrid, Spain
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This will probably won't help you directly. I've never tried multiple includes which have opened { and they're closed later on. But I'm guessing PHP tries to verify each included file before going to the next include and that's why it's giving you an error there. Again, this is something I've never done so maybe include doesn't behave like that.

    In any case, as good practice, each script (.php) should be able to run by itself without any errors, after that, you could do whatever you want with them.

    Does Internet Explorer not like closing in other files?!?
    No, Internet Explorer, nor any other web browser, has anything to do with PHP's include. This is part of PHP, as I said before.

  3. #3
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,099
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you are trying to close this brace,
    Code:
    while($row = mysql_fetch_array($data)){
    outside of an include, no this will not work. Braces must be balanced in each complete file.
    What I lack in acuracy I make up for in misteaks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •