How to add to cart without reload page using php code

we are add to cart in e-commerce website without reload page use the php simple code. and get id the cart in session that are the send value through cart button with session.

//Get session value

if(isset($_GET['action']) && $_GET['action']=="add"){
//Get product id
$sql_p="SELECT * FROM products WHERE id={$id}";
$_SESSION['cart'][$row_p['id']]=array("quantity" =>1, "price" => $row_p['product_price']);
$message="Product ID is invalid";
// Html code add to cart

<input class="input-text qty text" type="number" size="4" title="Qty" value="1" name="qty" min="1" step="1" max="5" />
<a href="#emptycart" class="btn btn-primary btn-lg" />add to cart</a>

Social Share

Leave a Comment