解析错误:语法错误,第14行的C:\ xampp \ htdocs \ database.php中的意外$ end

时间:2012-11-30 07:11:15

标签: php

我是php的新手并且自己学习它。

我收到了上述错误。我确实尝试了所有谷歌建议,但无法解决。 需要帮忙。无法继续下去!

第14行将是“$ category = $ category-> fetch();”

<?php>
require 'database.php';

//get category ID
$category_id = $_GET['category_id'];
if(!isset($category_id)) {
$category_id = 1;
}

//Get name for current category
$query = "SELECT * FROM categories
      WHERE categoryID = $category_id";
 $category = $db->query($query);
 $category = $category->fetch();
 $category_name = $category['categoryName'];

 //Get all categories
 $query = 'SELECT * FROM categories
      ORDER BY categoryID';
 $categories = $db->query($query);

 //Get all products for selected category
$query = "SELECT * FROM products 
     WHERE categoryID = $category_id
     ORDER BY productID";
 $products = $db->query($query);

?>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitionl.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--the head section -->
<head>
<title>My Guitar Shop</title>
<link>rel = "stylesheet" type ="text/css" href = main.css"/>
</head>

<!-- the body section -->
<body>
<div id = "page">
<div id = "main">

 <h1>Product List</h1>
 <div id = "sidebar"> 

 <!-- display a list of categories -->
 <h2> Categories</h2>
 <ul class = "nav">
 <?php foreach (categories as $category):?>
 <li>
 <a ref = "?category_id =<?php echo $category['categoryID'];?>">
 <?php echo $category['categoryName'];?>
 </a>
 </li>
 <?php endforeach;?>
 </ul>
 </div>

      <div id = "content">
     <!-- display a table of products -->
 <h2><?php echo $category_name;?></h2>
 <table>
 <tr>
    <th> Code</th>
    <th>Name</th>
    <th class = "right">Price</th>
 </tr>

 <?php foreach($products as $product):?>
 <tr>
     <td><?php echo $product['productCode'];?></td>
     <td><?php echo $product['productName'];?></td>
     <td class="right"><?php echo $product['listPrice'];?></td>
</tr>
    <?php endforeach;?>
     </table>   
</div>
     <div id ="footer"></div>
  </div><!--end page-->
  </body>
 </html>

2 个答案:

答案 0 :(得分:1)

<?php foreach (categories as $category):?>
在变量名称类别之前

缺少$符号

答案 1 :(得分:0)

它认为你错过了“;”在“database.php”文件中的13行左右。检查后。

如果您提供“database.php”文件代码,我们可以帮助解决问题所在。