Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我能';当用户更改他/她购买的产品数量时,是否在数据库中更新我的购物篮(使用ajax!)?_Php_Jquery_Mysql_Ajax - Fatal编程技术网

Php 我能';当用户更改他/她购买的产品数量时,是否在数据库中更新我的购物篮(使用ajax!)?

Php 我能';当用户更改他/她购买的产品数量时,是否在数据库中更新我的购物篮(使用ajax!)?,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,我有一个网上商店。在用户篮中,用户添加了一些产品。现在他/她想改变(增加或减少)产品的数量。我已经用ajax编写了这一部分,但它不起作用。一切似乎都是对的!我不知道怎么了!请帮帮我 最后,我添加了“update_order.php”页面的代码 $(文档).ready(函数(){ $(“.navbar right li.navbar brand”).hide(); }); سبد خرید فروشنده توضیحات کالا تعداد قیمت واحد قیمت کل "> تومان

我有一个网上商店。在用户篮中,用户添加了一些产品。现在他/她想改变(增加或减少)产品的数量。我已经用ajax编写了这一部分,但它不起作用。一切似乎都是对的!我不知道怎么了!请帮帮我

最后,我添加了“update_order.php”页面的代码


$(文档).ready(函数(){
$(“.navbar right li.navbar brand”).hide();
});
سبد خرید
فروشنده
توضیحات کالا
تعداد
قیمت واحد
قیمت کل
">
تومان
تومان
无功定时器;
函数jam_kharid(){
风险价值金额=0;
var买入金额=0;
清除超时(计时器);
计时器=设置超时(函数(){
$(“.pitem”)。每个(函数(索引,元素){
var pcount=$(this.find(#pcount”).val();
var pprice=$(this.find(#pprice”).text();
金额=金额+帕塞因特(pcount)*帕塞因特(pprice);
购买金额=(1.09*金额).toFixed(0);
});//每个pitem函数
$(“.pitem.pcount”).change(函数(){
var pcount=$(this.val();
var pprice=$(this.parents(“.pitem”).find(“#pprice”).text();
var kol_price=parseInt(pcount)*parseInt(pprice);
$(this.parents(“.pitem”).find(“#kol_price”).text(kol_price);
贾姆·哈里德();
//****************************************************************************************************************      
var productcount=pcount;
var productid=$(“#pcount”).parents(“.pitem”).attr('id');
警报(productid);
$.ajax({
url:'update_order.php',
类型:'POST',
数据:{productid:productid,cookiename:,productcount:productcount}
})//阿贾克斯
.done(函数(msg){
警报(msg);
})//完成
//****************************************************************************************************************              
})改变
$(“.jamkharid”).find(“#jam_kharid”).html(金额);
$('.jamkharid').find(“#maliat”).text(金额*0.09);
$('.jamkharid').find('jam#u kharid_final').text((1.09*amount).toFixed(0));
},600);
}//贾穆·哈里德
贾姆·哈里德();
函数khali(){
var l=$('.pitem').length;
如果(l==0){
本次(300)现场展示(300)美元(“#厄尔-厄尔-厄尔-厄尔-厄尔尔-空空-厄尔尔))的现场展示(“#厄尔-厄尔-厄尔-厄尔-厄尔-厄尔-厄尔-厄尔-厄尔-厄尔-厄尔-厄尔-厄尔-厄尔-今年今年今年(3月))的。展示(300)。展示(300)展示(300)现场(300)展示(300)现场(300)现场(300)现场(300)现场(300)现场(300)现场(300)现场(300)现场(300)现场(300)美元((((((300)现场(300)现场(300)现场(300)本本本本本本本本本本本本本本本本本本本本本本本本本本本本本本币(300)))))))))))))))))))(((300(300)))اشد!);
$('.my_table').hide();
$('.jamkharid').hide();
}
}//函数p_长度
khali();
$(“.remove”)。单击(函数(){
var id_pitem=$(this).parents(“.pitem”).attr('id');
var pitem_parent=$(this.parents(“.pitem”);
$.ajax({
url:'delete.php',
类型:'POST',
数据:{id:id_pitem}
})//阿贾克斯
.done(函数(){
pitem_parent.remove();
警觉(‘警觉’);
贾姆·哈里德();
khali();
})//完成
})//删除单击功能
功能检查编号(e){
如果((e.keyCode==65&&e.ctrlKey)| |(e.keyCode>=35&&e.keyCode

不起作用?发生了什么?给我们一个提示!如何创建一个你能在注释中阅读代码吗?你正在使用一些非标准的查询类,所以你最好告诉我们,我们不知道
->myquery()方法是什么。我在顶部的其他代码下面添加了update\u order.php代码。myquery()方法的工作是更新、删除并插入到我的数据库中。
   <?php
    if (session_status() == PHP_SESSION_NONE) {
        session_start();
    }

    include('database.php');
    $object=new myclass_parent;

    ?>
    <html>
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="X-UA-Compatible" content="IE=edge" />
            <meta name="viewport" content="width=device-width, initial-scale=1" />
            <script src="js/jquery.min.js"></script>
            <script src="js/bootstrap.min.js"></script>
            <link rel="stylesheet" type="text/css" href="css/style.css" />
            <link href="css/bootstrap.min.css" rel="stylesheet"/>
            <link href="css/bootstrap.rtl.min.css" rel="stylesheet"/>
            <script type="text/javascript">
                $(document).ready(function () {
                    $(".navbar-right li .navbar-brand").hide();
                });
            </script>
            <title></title>
        </head>
        <body>

            <?php

            include('header.php');

            ?>


            <!--------------------------------->
            <!--------------------------------->
            <!--------------------------------->
            <!--------------------------------->
            <!--------------------------------->


            <div class="container content info">
                <h4>سبد خرید</h4>

                <div class="row">

                <div style="display:none;margin-top:10px;" id="err_alert" class="alert alert-danger ">
                                <span id="empty_err"> </span> 

                 </div> 

                    <div class="table-responsive">          
                      <table class="table my_table">
                        <thead>
                          <tr>
                            <th>فروشنده</th>
                            <th>توضیحات کالا</th>
                            <th>تعداد</th>
                            <th>قیمت واحد</th>
                            <th colspan="2">قیمت کل</th>
                          </tr>
                        </thead>
                        <tbody>



                        <?php


                        if(isset($_COOKIE['mybasket'])){



                            $query="select * from tblbasket where cookiename=? and payment=0";
                            $array=[$_COOKIE['mybasket']];
                            $result_array=$object->select($query,$array);

                            foreach($result_array as $result){

                                $productid=$result['productid'];
                                $count=$result['count'];

                                $query2="select * from tblproducts where id=?";
                                $array2=[$productid];
                                $result_array2=$object->select($query2,$array2);

                                $img=$result_array2[0]['img'];
                                $title=$result_array2[0]['title'];
                                $price=$result_array2[0]['price'];
                                $info=$result_array2[0]['info'];
                                ?>

                                <tr id="<?php echo $productid; ?>" class="pitem">

                                <td rowspan=''><a href="http://amazoon.com">amazoon.com</a></td>

                                     <td>
                                        <img src="<?php echo $img; ?>" width="100" height="80"/>
                                        <div>
                                            <strong><?php echo $title; ?></strong>
                                            <p><?php echo $info; ?></p>
                                        </div>
                                     </td>
                                <td>
                                <input style="width:50px" type="number" id="pcount" class="pcount" 
                                onKeyDown="return checknumber(event);"  min="1" value="<?php  echo $count; ?>">
                                </td>
                                <td><span id="pprice"><?php echo $price; ?></span> تومان</td>
                                <td><span id="kol_price"><?php echo $count*$price; ?></span> تومان</td>
                                <td><a style="cursor:pointer;" class="remove"><img src="images/delete.png" alt="حذف محصول" title="حذف محصول"/></a></td>';


                        <?php       
                            }//foreach
                         ?>





                        </tr><!--basket_items-->


                        </tbody>
                      </table>



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

                <?php

                        }//isset cookie


                        ?>


                <div class="row">
                <div class="col-12">
                    <table class="table-responsive tbl jamkharid">
                        <thead>
                        <tr><th>پیش فاکتور خرید</th></tr>
                        <tr><th>مبلغ کل</th><th>مالیات 9%</th><th>هزینه ارسال</th>           <th>مبلغ پرداختی نهایی</th></tr>
                        </thead>
                        <tbody>
                        <td><span id="jam_kharid"></span> تومان</td><td><span id="maliat"></span> تومان</td>
                        <td><span id="delivery">0</span> تومان</td><td><span id="jam_kharid_final"></span> تومان</td>
                        </tbody>

                    </table>
                </div><!--col12-->
                </div><!--row-->

                <div class="row">
                    <?php if(isset($_SESSION['email'])){ ?>

                    <a href="info.php" class="button">مرحله بعد</a>

                 <?php }//if
                        else{
                  ?>

                  <a href="login_register.php" class="button">مرحله بعد</a>

                  <?php }//else ?>
                </div>
            </div>
            <!--------------------------------->
            <!--------------------------------->
            <!--------------------------------->
            <!--------------------------------->
            <!--------------------------------->
            <?php
            include('footer.php');
            ?>
        </body>
        </html>

        <script>

        var timer;

       function jam_kharid(){

        var amount=0;
        var buy_amount=0;

        clearTimeout(timer);
        timer=setTimeout(function(){

            $(".pitem").each(function(index, element) {


                var pcount=$(this).find("#pcount").val();
                var pprice=$(this).find("#pprice").text();

                amount=amount+parseInt(pcount)*parseInt(pprice);    

                buy_amount=(1.09*amount).toFixed(0);

            });//each pitem function


                $(".pitem .pcount").change(function(){

                    var pcount=$(this).val();
                    var pprice=$(this).parents(".pitem").find("#pprice").text();

                    var kol_price=parseInt(pcount)*parseInt(pprice);
                    $(this).parents(".pitem").find("#kol_price").text(kol_price);

                    jam_kharid();
    //****************************************************************************************************************      

                    var productcount=pcount;
                    var productid=$("#pcount").parents(".pitem").attr('id');

                    alert(productid);

                    $.ajax({

                        url:'update_order.php',
                        type:'POST',
                        data:{productid:productid,cookiename:<?php echo $_COOKIE['mybasket']; ?>,productcount:productcount}

                    })//ajax
                    .done(function(msg){

                        alert(msg);

                    })//done

    //****************************************************************************************************************              
                });//change



                $(".jamkharid").find("#jam_kharid").html(amount);

                $('.jamkharid').find("#maliat").text(amount*0.09);

                $('.jamkharid').find("#jam_kharid_final").text((1.09*amount).toFixed(0));



        },600);

    }//jam_kharid


    jam_kharid();




    function khali(){
    var l=$('.pitem').length;

    if(l==0){

        $('#err_alert').show(300); $('#err_alert #empty_err').show(); $('#err_alert #empty_err').html('هیچ محصولی در سبد خرید شما موجود نمی باشد!');

        $('.my_table').hide();

        $('.jamkharid').hide();
    }

    }//function p_length

    khali();

    $(".remove").click(function(){

        var id_pitem=$(this).parents(".pitem").attr('id');
        var pitem_parent=$(this).parents(".pitem");

        $.ajax({

            url:'delete.php',
            type:'POST',
            data:{id:id_pitem}

        })//ajax
        .done(function(){

            pitem_parent.remove();

            alert('محصول مورد نظر حذف شد');

            jam_kharid();
            khali();

        })//done

    })//remove click function



    function checknumber(e){

        if( (e.keyCode==65 && e.ctrlKey) || (e.keyCode>=35 && e.keyCode<=40) || ($.inArray(e.keyCode,[8,46])!=-1) ){

            return;

        }//if

        if( e.shiftKey || ((e.keyCode<48 || e.keyCode>57) && (e.keyCode<96 || e.keyCode>105)) ){
            e.preventDefault();
        }//if

    }//checknumber

    </script>

////////////////////////////////////////////////////////////////////////////////
update_order.php :
////////////////////////////////////////////////////////////////////////////////
<?php
 include('database.php'); 
$object=new myclass_parent; 
$product_id=intval($_POST['productid']);
 $cookie_name=$_POST['cookiename']; 
$product_count=intval($_POST['productcount']);

 $query_update="update tblbasket set count=? where cookiename=? and productid=? and payment=0"; 
$array=array($product_count,$cookie_name,$product_id);
 $object->myquery($query_update,$array); echo $product_id;

 ?>