繁体   English   中英

变量无法访问PHP函数中的内部查询

[英]Variable is not accessing inside query in php function

我使用ajax传递了一个变量以在我的php文件“ Cart_code.php”中运行。 为什么变量不能在函数内部访问?

Java脚本

$.ajax({
    type: "POST",
    url: "includes/Cart_code.php",
    data: {ID:id},
    success: function(result){
        console.log(result);
    }

});
     });

});
</script>

Cart_code.php

function cart_head_info_print()
{
    if(isset($_POST['ID']))
    { 
        //Here the id is accessing. To make it accessible inside query, i made it global 
        echo $GLOBALS['pro_id'] = $_POST['ID'];
    }

    parent::db();
    $email = $_SESSION['email'];
    $pro_id =  $GLOBALS['pro_id'];

    $query = "SELECT product_name , product_description from cart WHERE u_email = '$email' and product_id = '$pro_id'";
}
    function cart_head_info_print(){
      //this is for debugging. If this is empty/null/etc then you have a problem

      var_dump($_POST['ID']);          


     //$_POST is a super global so you don't need to do anything special

                parent::db();
                $email = $_SESSION['email'];
                $pro_id =  $POST['ID'];

                $query = "SELECT product_name , product_description from cart WHERE u_email = '$email' and product_id = '$pro_id'";
    }
// if you truly are missing the function call then you need this too, but I don't think you're missing this
cart_head_info_print();

更新1

http://php.net/manual/zh/keyword.parent.php

我很肯定您使用的是parent::错误。 我将其删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM