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 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 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.

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.

If you are trying to close this brace,


while($row = mysql_fetch_array($data)){ 

outside of an include, no this will not work. Braces must be balanced in each complete file.