Basically, I’m creating an e-commerce website for a college project. My intent is that when a user clicks on the add to cart button, the name of the book and it’s price gets sent to an external php file which does the job of handling the cart logic. I’m using the $http service of AngularJS to do this but there is some issue.
Here is the basic function logic:
$scope.executefunc = function(name,price){
var data = {
action: 'setcart',
bname: name,
bprice: price
}
$http.post('cart.php',data)
.then(function(response){
alert(response.data);
},function(err){
console.error("Error:",err);
});
};
});
The php file gives me an error saying “Undefined array key ‘bname'(and bprice) in cart.php file”
Here is what the php file looks like:
<?php
session_start();
$name=$_POST['bname'];
$price=$_POST['bprice'];
echo $name;
echo $price;
What can I do here?