I created an add to cart function but not working properly
on submit i see these errors on the place of product details
Notice: Undefined variable: product_id in C:\wamp\www\connectdemo\product_details.php on line 218
etc etc....
product_details.php
<?php
session_start();
include_once("includes/layout/header.php");
include_once("includes/connection.php");
include_once("includes/functions.php");
if(isset($_POST["addtocart"])) {
$pid = $_POST["productid"];
$prod_name = $_POST["productname"];
$prod_price = $_POST["productprice"];
if(isset($_POST['command']) == 'add' && $_POST['productid']>0 ) {
$pid=$_POST['productid'];
echo addtocart($pid,1, $prod_name, $prod_price);
//exit();
}
}
?>
functions.php
function addtocart($pid,$q,$pname,$pprice){
if($pid<1 or $q<1) return;
if(is_array($_SESSION['cart'])){
if(product_exists($pid)) return;
$max=count($_SESSION['cart']);
$_SESSION['cart'][$max]['productid']=$pid;
$_SESSION['cart'][$max]['qty']=$q;
}
else{
$_SESSION['cart']=array();
$_SESSION['cart'][0]['productid']=$pid;
$_SESSION['cart'][0]['qty']=$q;
}
header("location:cart.php?pname=$pname&price=$pprice");
}