我的数据库中仅存储了1个项目

谢尔福特

checkout.php ......我使用此代码。当我购买2件或更多商品时,我的数据库中仅存储了1件商品。提前致谢...................

<?php
session_start();
include('conn.php');
require('item.php');
if(isset($_POST['confirm'])){
$order=$_POST['order'];
$date = date('Y-m-d H:i:s');
$lname=$_POST['lname'];
$fname=$_POST['fname'];
$mname=$_POST['mname'];
$add=$_POST['add'];
$em=$_POST['email'];
$num=$_POST['number'];
if(empty($order)){
echo"<script>alert('Please choose your payment method.')</script>";
}
mysqli_query($con,"INSERT INTO `godgets`.`order` (`Lastname`, `Firstname`, `Middlename`, `Address`, `Email`, `Number`, `Date`) VALUES ('$lname', '$fname', '$mname', '$add', '$em', '$num', '$date')");
$orderid=mysqli_insert_id($con);
$cart=unserialize(serialize($_SESSION['cart']));
for ($i=0; $i<count($cart); $i++) {
$p_name=$cart[$i]->name;
$p_price=$cart[$i]->price;
$p_des=$cart[$i]->des;
$p_quantity=$cart[$i]->quantity;
$p_image=$cart[$i]->image;
$p_total=$cart[$i]->price * $cart[$i]->quantity;
mysqli_query($con,"INSERT INTO order_details (`ORDER_ID`, `P_name`, `P_price`, `P_quantity`, `Picture`,`Total`) VALUES 
('.$orderid.', '$p_name.', '.$p_price.', '.$p_quantity.', '.$p_image.','.$p_total.')");
}
echo"<script>alert('Thankyou For Shopping!')</script>";
echo"<script>window.open('index.php','_self')</script>";
unset($_SESSION['cart']);
exit();
}
?>

请帮我,我是新手:( tnx

fds item.php

<?php
    class Item{
        var $id;
        var $name;
        var $des;
        var $quantity;
        var $price;
        var $image;
    }
?>

addcart.php

            <?php
            session_start();
            ?>
            <head>
            <meta name="viewport" content="width=device-width, initial-    scale=1">
              <link rel="stylesheet" type="text/css" href="css\bootstrap.min.css">
              <link rel="stylesheet" type="text/css" href="css\bootstrapValidator.min.css">
               <script src="jq/jquery.min.js"></script>
              <script src="js/bootstrap.min.js"></script>
              <script src="js/bootstrapValidator.min.js"></script>
            </head>
            <body background="pic/bg3.jpg" style="background-attachment:fixed;background-size:cover;">
            <?php include("navbar.php");
            require('conn.php');
            require('item.php');
            if(!isset($_SESSION['username'])){
                echo"<script>window.open('sign.php','_self')</script>";
            exit();
            }
            if(isset($_GET['id']) && !isset($_POST['update'])){
            $result=mysql_query('select * from products_db where P_ID ='.$_GET['id']);
            $product=mysql_fetch_object($result);
            $item= new Item();
            $item->id= $product->P_ID;
            $item->name=$product->P_NAME;
            $item->des=$product->DESCRIPTION;
            $item->price=$product->P_PRICE;
            $item->image=$product->PICTURE;
            $item->quantity=1;
            //check product
                $index=-1;
                $cart=unserialize(serialize($_SESSION['cart']));
                for($i=0; $i<count($cart);$i++)
                if ($cart[$i]->id==$_GET['id']){
                    $index=$i;
                    break;
                }
                if($index==-1){
                $_SESSION['cart'][]=$item;
                }
                else{
                $_SESSION['cart']=$cart;
                }
            }
            //delete
            if(isset($_GET['index']) && !isset($_POST['update'])){
            $cart=unserialize(serialize($_SESSION['cart']));
            unset($cart[$_GET['index']]);
            $cart=array_values($cart);
            $_SESSION['cart']=$cart;
            }
            if (isset($_POST['update'])){
                $arrQuantity=$_POST['quantity'];
                // check quantity
                $valid=1;
                for($i=0; $i<count($arrQuantity);$i++)
                    if(!is_numeric($arrQuantity[$i]) || $arrQuantity[$i]< 1){
                    $valid=0;
                    break;
                }
                if($valid==1){
                $cart=unserialize(serialize($_SESSION['cart']));
                for($i=0; $i<count($cart);$i++){
                    $cart[$i]->quantity=$arrQuantity[$i];
                }
                $_SESSION['cart']=$cart;
                }
                else
                    $error='Quantity is Invalid';
            }
            ?>
            <div class="container">
                <div class="row">
                    <div class="col-md-12 col-xs-12">
                        <div class="panel panel-info">
                          <div class="panel-heading">
                          <form method="POST">
                            <div class="panel-title">
                                        <h5><span class="glyphicon glyphicon-shopping-cart" style="float:left;"></span>&nbsp;YOUR ITEM(s)
                                        <label style="color:red;margin-left:400px;"><?php echo isset($error) ? $error : '';?></label>
                                        <a href="producthot.php" style="float:right;"class="btn btn-success btn-sm "><span class="glyphicon glyphicon-share-alt"></span> Continue Shopping</a>
                                        <button type="submit" name="update" style="float:right; margin-right:3%;"class="btn btn-info btn-sm "><span class="glyphicon glyphicon-floppy-saved"></span>Update Cart</button>
                                        </h5>               
                            </div>
                        </div>
                        <?php
                        $cart=unserialize(serialize($_SESSION['cart']));
                        $s=0;
                        $index=0;
                        for ($i=0;$i<count($cart); $i++){
                            $s+=$cart[$i]->price * $cart[$i]->quantity;

                        ?>
                        <div class="panel-body">
                                <div class="row">
                                    <div class="col-md-2 col-xs-12">
                                        <img class="img-responsive" src="<?php echo $cart[$i]->image;?>" style="height:30%;width:100%;">
                                    </div>
                                        <div class="col-md-4 col-xs-12">
                                            <h4 style="font-family:agency fb;"><strong><?php echo $cart[$i]->name;?></strong></h4>
                                            <div><h4 style="font-family:agency fb;"><small><?php echo $cart[$i]->des;?></small></h4></div>
                                        </div>
                                        <div class="col-md-6 col-xs-12">
                                        <div class="col-md-6 text-right">
                                                <h4 style="font-family:agency fb;"><strong>Php <?php echo $cart[$i]->price;?></strong> x </h4>                                  
                                        </div>
                                        <div class="col-md-4 col-xs-9">
                                        <input type="text" name="quantity[]" value="<?php echo $cart[$i]->quantity;?>" class="form-control" style="width:50px;">
                                        </div>
                                        <div class="col-md-3 col-xs-2" style="margin-top:1%;">
                                        <a href="addcart.php?index=<?php echo $index;?>" onclick="return confirm('Are you sure?')" class="btn btn-danger btn-sm" style="width:50px;"><span class="glyphicon glyphicon-trash"></span></a>
                                    </div>
                                    </div>
                                </div>
                        </div>
                        <hr class="divider">
                        <?php
                        $index++;
                        }
                        ?>
                        </form>
                    <div class="panel-footer" style="height:9%;">
                    <div><a href="emptycart.php?action=empty" class="btn btn-danger" style="float:left;font-family:agency fb;">Empty Cart</a></div>
                    <div><a href="" data-toggle="modal" data-target=".bs-example-modal-sm" class="btn btn-success" style="float:right;font-family:agency fb;">Checkout</a></div>
                    <div style="float:right;margin-right:2%;font-family:agency fb;"><p class="form-control"><b>Total</b> Php: <?php echo $s;?></p></div>
                    </div>
                    </div>
                    </div>
                </div>
            </div>
                    <div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
                          <div class="modal-dialog modal-lg">
                            <div class="modal-content">
                               <div class="modal-header" style="background-color:#cceaf6;">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="myModalLabel" style="font-family:agency fb;font-size:30px;">Costumer`s Information</h4>
                                  </div>
                                  <form method="POST" action="checkout.php">
                                  <div class="modal-body">
                                <div class="form-group">
                                <div class="row col-md-12">
                                    <div class="container inline col-md-4" >
                                            <input type="radio" class="form-control" name="order" onclick="showhidediv(this);" value="paypal">
                                            <img src="pic/paypal.jpg" style="width:200px;height:100px;">
                                    </div>
                                    <div class="col-md-4">
                                    <center><span style="font-family:agency fb; font-size: 50px;">or</span></center>
                                    </div>
                                    <div class="col-md-4">
                                            <input type="radio" class="form-control" name="order" onclick="showhidediv(this);" value="Cash On Delivery">
                                            <img src="pic/cash.png" style="width:200px;height:100px;">
                                    </div>
                                </div>
                                <div class="form-inline">
                                    <input type="text" class="form-control" name="lname" placeholder="Lastname" required>

                                    <input type="text" class="form-control" name="fname" placeholder="Firstname"required>

                                    <input type="text" class="form-control" name="mname" placeholder="Middlename"required>
                                </div>
                                <br>
                                    <input type="text" class="form-control" name="add" placeholder="Complete Address" style="width:596px;"required>
                                <br>
                                    <input type="email" class="form-control" name="email" placeholder="Email Address"style="width:596px;"required>
                                <br>                    
                                <input type="text" class="form-control" name="number" placeholder="Contact Number"style="width:196px;" required>
                                <br>
                                <div id="one" style="display:none;">
                                <div style="background-color:#cceaf6;"><p>Bill to another address. (Optional)</p></div>
                                    <div class="form-inline">

                                    <input type="text" class="form-control" name="lname2" placeholder="Lastname">

                                    <input type="text" class="form-control" name="fname2" placeholder="Firstname">

                                    <input type="text" class="form-control" name="mname2" placeholder="Middlename">
                                </div>
                                <br>
                                    <input type="text" class="form-control" name="add2" placeholder="Complete Address" style="width:596px;">
                                <br>
                                    <input type="email" class="form-control" name="email2" placeholder="Email Address"style="width:596px;">
                                <br>                    
                                <input type="text" class="form-control" name="number2" placeholder="Contact Number"style="width:196px;">
                                 </div>
                                 </div>
                            </div>
                            <div class="modal-footer">
                                    <button type="submit" name="confirm" class="btn btn-success" style="font-family:agency fb;font-size:15px;width:100px;">OK</button>
                                  </div>
                                  </form>
                          </div>
                        </div>
            </body>
            <script>
            function goBack() {
                window.history.back();
            }
            function showhidediv( rad )
                {
                    var rads = document.getElementsByName( rad.name );
                    document.getElementById( 'one' ).style.display = ( rads[1].checked ) ? 'block' : 'none';
                }
            </script>

错误

only 1 item stored.
法赫鲁丁·乌贾因瓦拉

嗨,您需要纠正此问题: '.$cart[$i]->image.'

for ($i=0; $i<count($cart); $i++) {
mysql_query("INSERT INTO order_details VALUES ('.$orderid.', '.$cart[$i]->name.', '.$cart[$i]->price.', '.$cart[$i]->quantity.', '.$cart[$i]->image.', '.$cart[$i]->price * $cart[$i]->quantity.','.$order.')");
}

另外,下次您提出此类问题时,请在代码中突出显示错误行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我的数据库中仅存储了1个项目

来自分类Dev

变量仅存储 Firebase 数据库的最后一个值

来自分类Dev

在数据库中仅存储没有时间的日期

来自分类Dev

向DataSet添加了多条记录,但数据库(C#)中仅存储了一条记录

来自分类Dev

在Java的ArrayList中存储MySQL数据库项目

来自分类Dev

我想将四个即将到来的日期存储到数据库中吗?

来自分类Dev

我只能将数字存储在数据库中,而php是一个简单的shoutbox

来自分类Dev

在Access的一个数据库字段中存储多个值(听我说)

来自分类Dev

在我的 MongoDB 数据库中存储一个带有 PYmongo 错误的 PDF 文件

来自分类Dev

如何确定我的数据存储在elgg数据库中?

来自分类Dev

我的数据未存储在数据库中

来自分类Dev

我应该在网站上使用 JavaScript 数组来存储数据库中的项目数据吗?

来自分类Dev

我如何从数据库中删除recyclerView中的项目

来自分类Dev

1个项目中的多领域数据库

来自分类Dev

1个项目中的多领域数据库

来自分类Dev

当我从数据库中删除一个项目并更新数据网格时,我仍然看到这个对象

来自分类Dev

获取存储在我的数据库中的文件的大小

来自分类Dev

我可以在另一个SQLite数据库中存储一个SQLite数据库吗?

来自分类Dev

SQLite数据库仅存储通过ContentProvider发送的最后一条记录

来自分类Dev

我需要一个C#函数来返回在MongoDB数据库中输入的最后N个项目

来自分类Dev

当追加1个以上div时,下拉选项会增加,我从数据库中检索

来自分类Dev

MySQL php 从数据库中获取项目并存储在 XML 中(重复项目)

来自分类Dev

在2个数据库之间共享1个存储库

来自分类Dev

我想将列表视图中显示的项目列表存储到android Sqlite数据库

来自分类Dev

如何在我的 java 项目中存储数据库密码和用户名?

来自分类Dev

尝试通过存储库编辑我的数据库中的数据时获得豁免

来自分类Dev

Sitecore将项目统计数据存储在数据库中的什么位置?

来自分类Dev

基于Json文件中存储的元数据创建数据库模式的PHP项目的名称?

来自分类Dev

我应该将Type存储在数据库中还是应该将其存储在枚举中?

Related 相关文章

  1. 1

    我的数据库中仅存储了1个项目

  2. 2

    变量仅存储 Firebase 数据库的最后一个值

  3. 3

    在数据库中仅存储没有时间的日期

  4. 4

    向DataSet添加了多条记录,但数据库(C#)中仅存储了一条记录

  5. 5

    在Java的ArrayList中存储MySQL数据库项目

  6. 6

    我想将四个即将到来的日期存储到数据库中吗?

  7. 7

    我只能将数字存储在数据库中,而php是一个简单的shoutbox

  8. 8

    在Access的一个数据库字段中存储多个值(听我说)

  9. 9

    在我的 MongoDB 数据库中存储一个带有 PYmongo 错误的 PDF 文件

  10. 10

    如何确定我的数据存储在elgg数据库中?

  11. 11

    我的数据未存储在数据库中

  12. 12

    我应该在网站上使用 JavaScript 数组来存储数据库中的项目数据吗?

  13. 13

    我如何从数据库中删除recyclerView中的项目

  14. 14

    1个项目中的多领域数据库

  15. 15

    1个项目中的多领域数据库

  16. 16

    当我从数据库中删除一个项目并更新数据网格时,我仍然看到这个对象

  17. 17

    获取存储在我的数据库中的文件的大小

  18. 18

    我可以在另一个SQLite数据库中存储一个SQLite数据库吗?

  19. 19

    SQLite数据库仅存储通过ContentProvider发送的最后一条记录

  20. 20

    我需要一个C#函数来返回在MongoDB数据库中输入的最后N个项目

  21. 21

    当追加1个以上div时,下拉选项会增加,我从数据库中检索

  22. 22

    MySQL php 从数据库中获取项目并存储在 XML 中(重复项目)

  23. 23

    在2个数据库之间共享1个存储库

  24. 24

    我想将列表视图中显示的项目列表存储到android Sqlite数据库

  25. 25

    如何在我的 java 项目中存储数据库密码和用户名?

  26. 26

    尝试通过存储库编辑我的数据库中的数据时获得豁免

  27. 27

    Sitecore将项目统计数据存储在数据库中的什么位置?

  28. 28

    基于Json文件中存储的元数据创建数据库模式的PHP项目的名称?

  29. 29

    我应该将Type存储在数据库中还是应该将其存储在枚举中?

热门标签

归档