嗨,我有未定义的变量:<p>品牌:<! - ?php echo $ brand ['brand']; ? - > </p>

时间:2018-06-05 12:51:15

标签: php mysqli

<?php 

    require_once 'core/init.php';

    if(isset($_POST['modalBtn']))
    {
        $id = $_GET['id'];
        $id = (int)$id;
        $sql = "SELECT * FROM products WHERE id = '$id'";
        $result = $db->query($sql);
        $product = mysqli_fetch_assoc($result);  
        $brand_id =  $product['brand'];

        $sql = "SELECT brand FROM brand WHERE id = '$brand_id'";
        $brand_query = $db->query($sql);
        $brand = mysqli_fetch_assoc($brand_query);
    }

 ?>

<!--Modal-->
<?php ob_start(); ?>
        <div class="modal fade detail-1" id="details-1" tabindex="-1" role="dialog" arial-labelledby="details-1" arial-hidden="true">
            <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" type="button" data-dismiss="modal" arial-label="Close">
                        <span arial-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title text-center"><?= $product['title']; ?></h4>
                </div>
                <div class="modal-body">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="center-block">
                                    <img src="<?= $product['image']; ?>" alt="<?= $product['title']; ?>" class="details img-responsive">
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <h4>Details</h4>
                                <p><?=$product['description']; ?></p>
                                <hr>
                                <p>Price: $<?= $product['price']; ?></p>
                                <p>Brand: <?php echo $brand['brand']; ?></p>
                                <form action="add_cart.php" method="post">
                                    <div class="form-group">
                                        <div class="col-xs-3">
                                            <label for="quantity">Quantity</label>
                                            <input type="text" class="form-control" name="quantity" id="quantity">
                                        </div>
                                        <br>
                                        <p><b>Available:</b>  3</p> 
                                    </div>
                                    <div class="form-group">
                                        <label for="size">Size</label>
                                        <select name="size" id="size" class="form-control">
                                            <option value=""></option>
                                            <option value="28">28</option>
                                            <option value="32">32</option>
                                            <option value="36">36</option>

                                        </select>
                                    </div>
                                </form>

                            </div>
                        </div>  
                    </div>
                </div>

                <div class="modal-footer">
                    <button class="btn btn-default" data-dismiss="modal">Close</button>
                    <button class="btn btn-warning" type="submit"><span class="glyphicon glyphicon-shopping-cart"></span>Add To Cart</button>
                </div>
                </div>
            </div>
        </div>
        <!--end modal-->
       <?php echo ob_get_clean(); ?>

0 个答案:

没有答案