邮政编码干扰表

时间:2018-04-05 04:53:05

标签: php

在我的旧代码中,用户可以购买任意数量的代码,但在新代码中,用户必须只输入少于股票的数字。 我不确定这是不是问题。 不知何故,购买没有进入销售表中的销售总额。

在history.php中,总购买价格没有显示,但是当您点击查看完整详细信息按钮时,您可以看到总购买量。

History.php History

查看完整详情 Full Detail

销售表。 Sales Table

这是我的旧代码add_cart.php代码 在这里插入很好。

<?php
    include('session.php');
    if(isset($_POST['cart'])){
        $id=$_POST['id'];
        $qty=$_POST['qty'];

        $query=mysqli_query($conn,"select * from cart where productid='$id' and userid='".$_SESSION['id']."'");
        if (mysqli_num_rows($query) > ($qty)){
            echo "Input must be lower than the quantity!";
        }
        else{
            mysqli_query($conn,"insert into cart (userid, productid, qty) values ('".$_SESSION['id']."', '$id', '$qty')");
        }
    }

?>

这是我的新代码add_cart.php代码 在这里它没有正确插入。     

include('session.php');
if(isset($_POST['cart'])){
    $id=$_POST['id'];
    $qty=$_POST['qty'];
if($qty>0){//This Condition work for you

    $query=mysqli_query($conn,"select product_qty from product where productid='$id'");
$result=mysqli_fetch_object($query);
if($result->product_qty < $qty){
   echo 'Input must be lower than the stocks';
} else{
        $query=mysqli_query($conn,"select * from cart where productid='$id' and userid='".$_SESSION['id']."'");
        if (mysqli_num_rows($query)>0){
            echo "Product already on your cart!";
        }
        else{
            mysqli_query($conn,"insert into cart (userid, productid, qty) values ('".$_SESSION['id']."', '$id', '$qty')");
        }
  }
}
}

?>

history.php列出了表格

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#datepicker" ).datepicker();
  } );
  </script>
</head>
<body>

<p>Date: <input type="text" id="datepicker"></p>


</body>
</html>

<?php include('session.php'); ?>
<?php include('header.php'); ?>
<body>
<?php include('navbar.php'); ?>
<div class="container">
    <?php include('cart_search_field.php'); ?>
    <div style="height: 50px;"></div>
    <div class="row">
        <div class="col-lg-12">
           <center> <h1 class="page-header">Purchase History</h1></center>
        </div>
    </div>
                <!-- /.row -->
                <div class="row">
                <div class="col-lg-12">
                                <center>
 <form action="total_sales.php" method="post">
  From: <input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required pattern="[0-9]{4}+[0-9]+[0-9]"> To: <input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required pattern="[0-9]{4}+[0-9]+[0-9]">
  <input type="submit" value="Show Purchases" name="salesbtn" ></form></center>
                    <table width="100%" class="table table-striped table-bordered table-hover" id="historyTable">
                        <thead>
                            <tr>
                                <th class="hidden"></th>
                                <th>Purchase Date</th>
                                <th>Total Amount</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                                $h=mysqli_query($conn,"select * from sales where userid='".$_SESSION['id']."' order by sales_date desc");
                                while($hrow=mysqli_fetch_array($h)){
                                    ?>
                                        <tr>
                                            <td class="hidden"></td>
                                            <td><?php echo date("M d, Y - h:i A", strtotime($hrow['sales_date']));?></td>
                                            <td><?php echo number_format($hrow['sales_total'],2); ?></td>
                                            <td>
                                                <a href="#detail<?php echo $hrow['salesid']; ?>" data-toggle="modal" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-fullscreen"></span> View Full Details</a>
                                                <?php include ('modal_hist.php'); ?>
                                            </td>
                                        </tr>
                                    <?php
                                }
                            ?>
                        </tbody>
                    </table>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>


</div>
<?php include('script.php'); ?>
<?php include('modal.php'); ?>
<script src="custom.js"></script>
<script>
$(document).ready(function(){
    $('#history').addClass('active');

    $('#historyTable').DataTable({
    "bLengthChange": true,
    "bInfo": true,
    "bPaginate": true,
    "bFilter": true,
    "bSort": true,
    "pageLength": 7
    });
});
</script>
</body>
</html>

0 个答案:

没有答案