PHP str_replace无法使用$ _POST变量

Ive been racking my brain trying to solve this but it just doesn't want to work. for some reason when i manually set the values for the variables in str_replace it works, however, when i automatically set the values to equal a $_POST variable it simply does not work even though it seems that it is returning the same value.

Incorrect code below:

           $CSI = $_POST["CartSlotId"]; 
           $NewCartData = "".$ParOut_CartData2[0].",".$_POST["SCQuantity"].""; 
           $ParOut_CartData =  $row['Cart'];


           echo "<script type='text/javascript'>alert('".$CSI ."');</script>"; 
           /*$CSI will echo "5,3" */
           echo "<script type='text/javascript'>alert('".$NewCartData ."');</script>"; 
           /*$NewCartData will echo "5,9" */
           echo "<script type='text/javascript'>alert('".$ParOut_CartData ."');</script>"; 

           $CSI = (string)$CSI;
           $NewCartData = (string)$NewCartData;
           $ParOut_CartData = (string)$ParOut_CartData;

           $ParOut_CartData3 = str_replace($CSI,$NewCartData,$ParOut_CartData);

Working code below:

       $CSI = "5,3";
       $NewCartData = "5,9";
       $ParOut_CartData =  $row['Cart'];

       $ParOut_CartData3 = str_replace($CSI,$NewCartData,$ParOut_CartData);

So why is it when i manually set the variable values it will work, but when i set them to the $_POST variable value str_replace stops working? any help?