vinpkl Posted September 28, 2012 Share Posted September 28, 2012 (edited) hi all i want to add multiple products using selected checkboxes to cart i m passing checkbox values from product page to cart page <input type="checkbox" value="1" name="related[]" /> <input type="checkbox" value="2" name="related[]" /> <input type="checkbox" value="3" name="related[]" /> <input type="submit" value="addtocart"> i tried below code in "cart.php" but this code output "ids" as array <? $related_all = array(); $related_all = $_REQUEST['related']; foreach($_REQUEST['related'] as $product_id) { if(isset($_REQUEST['related'])) { $id=$_REQUEST['related']; echo $id; /* ouput as ArrayArrayArray */ $qry = "select * from product_table where product_id = $id"; echo $qry; /* output = where product_id = Array */ } } ?> vineet Edited September 28, 2012 by vinpkl Quote Link to comment https://forums.phpfreaks.com/topic/268884-pass-multiple-ids-from-product-page-to-cart-page/ Share on other sites More sharing options...
spertuit Posted September 28, 2012 Share Posted September 28, 2012 Im just guessing at this, but when you are using "echo $id" and "echo $qry", aren't these arrays. You should be using a print_r ($id) or print_r ($qry) Quote Link to comment https://forums.phpfreaks.com/topic/268884-pass-multiple-ids-from-product-page-to-cart-page/#findComment-1381581 Share on other sites More sharing options...
Christian F. Posted September 28, 2012 Share Posted September 28, 2012 While $qry isn't an array, $id is. What you need here, is to use array_map (), intval (), implode () and MySQL's IN(). First two for security reasons, latter two to make the correct SQL query. Quote Link to comment https://forums.phpfreaks.com/topic/268884-pass-multiple-ids-from-product-page-to-cart-page/#findComment-1381583 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.