I passed a variable using ajax to function inside my php file "Cart_code.php". Why variable is not accessing inside the function?
Javascript
$.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();
UPDATE 1
http://php.net/manual/en/keyword.parent.php
I'm pretty positive you are using parent::
incorrectly. I would remove it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.