[英]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.