StayG Posted May 16, 2019 Share Posted May 16, 2019 When I send values to the foreach they are not recorded in the array. $x = $getProductID; $_SESSION['pColors'] = array(); if(isset($_POST['pColors'])) { foreach($_POST['pColors'] as $colorKey => $RColors) { $_SESSION['pColors'][$colorKey] = $RColors; } } var_dump($_SESSION['pColors']); Send date with AJAX: $('.addToCart').click(function(){ $.ajax({ url:""+realLink+"cart.php", method:"POST", data:{action:action,pColors:pColors}, success:function(data){ //alert(data); } }); }); Link to comment Share on other sites More sharing options...
Barand Posted May 16, 2019 Share Posted May 16, 2019 Check what is in $_POST['pcolors'] if(isset($_POST['pColors'])) { var_dump($_POST['pColors']); } Link to comment Share on other sites More sharing options...
StayG Posted May 16, 2019 Author Share Posted May 16, 2019 var_dump (); does not return anything inside this if. Because $ _POST is executed by ajax Link to comment Share on other sites More sharing options...
chhorn Posted May 16, 2019 Share Posted May 16, 2019 Doesn't matter. It is returned, you just don't look at it. Open the webdeveloper console and switch to the network tab. Link to comment Share on other sites More sharing options...
StayG Posted May 16, 2019 Author Share Posted May 16, 2019 array(1) { [3]=> array(4) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" [3]=> string(1) "4" } } It gets the values, but when it comes to the next spin, foreach replaces them. $i = 0; foreach($_SESSION['pID'] as $getProductID) { $x = $getProductID; //$_SESSION['pColors'] = array(); > this is when array is outside and stay empty if(isset($_POST['pColors'])) { $_SESSION['pColors'] = array(); // > this is when array is in and get values foreach($_POST['pColors'] as $colorKey => $RColors) { $_SESSION['pColors'][$x][$colorKey] = $RColors; } var_dump($_SESSION['pColors']); $i++; } In each case, values come to pColors but they are not recorded in the array. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.