function remove_from_cart($cart_id) { global $db; $query = "DELETE FROM `cart` WHERE id = '{$cart_id}'"; $result = $db->query($query); if ($result) { return array("success", get_cart_number()); } else { return array("failure"); } }
$numRows = $result->num_rows; if ($numRows > 0) { echo json_encode(array("failure")); } else { $query = "SELECT COUNT( id ) AS count, id FROM project_links WHERE user_id ='{$user_id}' AND project_id ='{$project_id}';"; $result = $db->query($query); //if(($result->fetch_assoc()['count']) == 0){ $query = "INSERT INTO `cart` ( `user_id` , `project_id` ) VALUES ('{$user_id}', '{$project_id}');"; $result = $db->query($query); if ($result) { $query = "SELECT name, price, id FROM project WHERE id ='{$project_id}'"; $project_name = $db->query($query); $var = $project_name->fetch_assoc(); $project_name = $var['name']; $project_price = $var['price']; $query = "SELECT id FROM cart WHERE project_id ='{$project_id}' AND user_id='{$user_id}';"; $cart_id = $db->query($query); $cart_id = $cart_id->fetch_assoc()['id']; $query = "INSERT INTO `project` ( `user_id` , `project_id` ) VALUES ('{$user_id}', '{$project_id}');"; $result = $db->query($query); echo json_encode(array("success", get_cart_number(), $cart_id, $project_name, $project_price, $project_id)); } else { echo json_encode(array("failure")); } // }else{ // echo json_encode(array("failure")); // } } } else { echo json_encode(array("authentication")); }
</div> <div class="modal-body"> <ul class="list-group" id="modal-cart-body"> <?php $result = get_elements_in_cart(); if (isset($result)) { $numRows = $result->num_rows; if ($numRows > 0) { while ($cart = $result->fetch_assoc()) { include '_cart.php'; } } else { echo '<h3 class="form col-md-12 center-block text-decore" id="no-elements"> No elements in cart</h3>'; } } ?> </ul> </div> <div class="modal-footer"> <div class="col-md-12" id="cart-footer"> <?php if (get_cart_number() > 0) { echo '<button class="btn btn-success btn-sm buy-all-cart" aria-hidden="true">Buy All</button>'; } ?> <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button> </div> </div> </div> </div> </div>