与电子商务网站相关的Php和引导程序代码

与电子商务网站相关的Php和引导程序代码,php,html,twitter-bootstrap,Php,Html,Twitter Bootstrap,嗨,我对PHP和Bootstrap非常陌生。我使用php和Bootstrap开发了一个电子商务网站。这个应用程序只需在购物车中来回添加和删除产品,还可以计算所有产品的总价格,如果用户有优惠券,他可以将其应用为“off30”,那么他将获得总价格的30%折扣。我遇到的错误是解析错误:语法错误,指向下面代码最后一行的意外文件结尾。请帮我解决这个错误 <?php session_start(); error_reporting("E_ALL"); require_once("dbcontrolle

嗨,我对PHP和Bootstrap非常陌生。我使用php和Bootstrap开发了一个电子商务网站。这个应用程序只需在购物车中来回添加和删除产品,还可以计算所有产品的总价格,如果用户有优惠券,他可以将其应用为“off30”,那么他将获得总价格的30%折扣。我遇到的错误是解析错误:语法错误,指向下面代码最后一行的意外文件结尾。请帮我解决这个错误

<?php
session_start();
error_reporting("E_ALL");
require_once("dbcontroller.php");
$conn = connectDB();
  if(!empty($_GET["action"])) {
     //echo $_GET["action"];
  switch($_GET["action"]) {
case "add":
    if(!empty($_POST["quantity"])) {
        $productByCode = mysqli_query($conn,"SELECT * FROM  tblproduct WHERE code='" . $_GET["code"] . "'");
                    $products = mysqli_fetch_array($productByCode);
        $itemArray = array($products["code"]=>array('name'=>$products["name"], 'code'=>$products["code"], 'quantity'=>$_POST["quantity"], 'price'=>$products["price"]));

        if(!empty($_SESSION["cart_item"])) {
            if(in_array($products["code"],array_keys($_SESSION["cart_item"]))) {
                foreach($_SESSION["cart_item"] as $k => $v) {
                        if($products[0]["code"] == $k) {
                            if(empty($_SESSION["cart_item"][$k]["quantity"])) {
                                $_SESSION["cart_item"][$k]["quantity"] = 0;
                            }
                            $_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];
                        }
                }
            } else {
                $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
            }
        } else {
            $_SESSION["cart_item"] = $itemArray;
        }
    }
break;
case "remove":
    if(!empty($_SESSION["cart_item"])) {
        foreach($_SESSION["cart_item"] as $k => $v) {
                if($_GET["code"] == $k)
                    unset($_SESSION["cart_item"][$k]);              
                if(empty($_SESSION["cart_item"]))
                    unset($_SESSION["cart_item"]);
        }
    }
break;
case "empty":
    unset($_SESSION["cart_item"]);
break;  
}
}

if($_SERVER['REQUEST_METHOD'] == 'POST'){
$coupon = $_POST["coupon"];
$total = $_POST["total"];
if($coupon == "off30"){
     $disc_item_total = $total*0.7;
}
else{
     $disc_item_total = $total;
}

if(!empty($product_数组))和while($products=…)循环未关闭。开始缩进代码可能是个好主意,这样您就可以看到什么东西关闭了,这确实有助于跟踪开始标记和结束标记。

在循环过程中,您永远不会关闭产品。让你找到一个好的IDE,它将突出你的编码问题。谢谢你的帮助。。现在代码正在运行。。我将遵循代码中的缩进。。。谢谢你的建议
?>


<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>All In One</title>

<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- Custom CSS -->
<link href="css/business-casual.css" rel="stylesheet">

<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Josefin+Slab:100,300,400,600,700,100italic,300italic,400italic,600italic,700italic" rel="stylesheet" type="text/css">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

</head>

<body>

<div class="brand">All In One</div>


<!-- Navigation -->
<nav class="navbar navbar-default" role="navigation">
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <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>
            <!-- navbar-brand is hidden on larger screens, but visible when the menu is collapsed -->
            <a class="navbar-brand" href="index.html">Business Casual</a>
        </div>
        <!-- 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">
                <li>
                    <a href="index.html">Home</a>
                </li>
                <li>
                    <a href="about.html">About</a>
                </li>
                <li>
                    <a href="blog.html">Blog</a>
                </li>
                <li>
                    <a id="btnEmpty" href="about.php?action=empty">Empty Cart</a>
                </li>
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

<?php
if(isset($_SESSION["cart_item"])){
$item_total = 0;
?>  

<div class="container">

    <div class="row">
        <div class="box">
            <div class="col-lg-12">
                <hr>
                <h2 class="intro-text text-center">
                    <strong>Products</strong>in Cart
                </h2>
                <hr>
            </div>

            <div class="col-md-6">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Code</th>
                            <th>Quantity</th>
                            <th>Price</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($_SESSION["cart_item"] as $item)
                        {
                    ?>
                            <tr>
                            <td><strong><?php echo $item["name"]; ?></strong></td>
                            <td > <?php echo $item["code"]; ?></td>
                            <td > <?php echo $item["quantity"]; ?></td>
                            <td > <?php echo "Rs.".$item["price"]; ?></td>
                            <td > <a href="about.php?action=remove&code=<?php echo $item["code"]; ?>">Remove Item</a></td>
                            </tr>
                            <?php
                            $item_total += ($item["price"]*$item["quantity"]);
                        }
                            ?>
                            <tr>    
                                <td colspan="3" align=right>Total:</td>
                                <td colspan="3"><b>Rs.=<?php $item_total;?></b></td>
                            </tr>
                            <tr>
                            <td colspan="3" align=right>Apply Coupon:</td>
                            <td>
                              <form action="" method="post">
                              <input type="text" id="coupon" name="coupon" value=""/>
                              <input type="hidden" name="total" value="<?php $item_total;?>">
                            </td>
                            <td>
                              <button type="submit" >Apply</button>
                                </form>
                            </td>
                            </tr>
                            <tr>
                                <td align=right colspan="3"> Discounted Amount:</td>
                                <td colspan="3"><b><?php "=Rs.".$disc_item_total; ?></b></td>
                            </tr>

                    </tbody>
                        <!--<?php echo $disc_item_total; ?>-->
                </table>        
                  <?php
                }
                ?>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>

    <div class="row">
        <div class="box">
            <div class="col-lg-12">
                <hr>
                <h2 class="intro-text text-center">
                    <strong>Products</strong>
                </h2>
                <hr>
            </div>

            <?php
                $product_array = mysqli_query($conn,"SELECT * FROM tblproduct ORDER BY id ASC");
                    //echo mysqli_num_rows($product_array);
                if (!empty($product_array)) { 
                    while($products = mysqli_fetch_array($product_array)){ 
            ?>

            <div class="col-md-3 col-sm-6 hero-feature">
            <div class="thumbnail">
                <form method="post" action="about.php?action=add&code=<?php echo $products["code"]; ?>">
                <div class="item active">
                            <img class="img-responsive img-full" src="img/a1.png" alt="">
                </div>
                <div class="caption">
                    <h4 class="pull-right"><?php echo "$".$products["price"]; ?></h4>
                    <h4><?php echo $products["name"]; ?></h4>
                    <div><input type="text" name="quantity" value="1" size="2" />
                    <p>
                       <input type="submit" value="Add to cart" class="btn btn-info" /></div>
                    </p>
                </div>
            </div>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>

</div>
<!-- /.container -->

<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <p>Copyright &copy; Your Website 2014</p>
            </div>
        </div>
    </div>
</footer>

<!-- jQuery -->
<script src="js/jquery.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>

</body>

</html>