Hello,

I am trying to pass multiple values, via an implode function. However, it isnt working. Here is the code from the first page, then the second page.

<?php
if(isset($_POST['numItems'])) {
$checkboxes = $_POST['numItems'];
$string = implode($value,"^");
echo $string; 
}
?> 

<form name='CartItem' action='https://www.ram-mount.com/RamCart/CartPutItem.php' method='POST'>
<input type='checkbox' name='numItems[]' value='RAM-VB-162'> 
<input type='checkbox' name='numItems[]' value='RAM-VB-154'>
<input type='submit' value='Add To Cart'>
</form>

Second Page:

<?php
include_once('./CartDBCxn.php');
if (!isset($_COOKIE['sess'])) {
    session_start();
    $usrSession = session_id();
    setcookie('sess',$usrSession,0,'/','ram-mount.com');
} else {
    $usrSession = $_COOKIE['sess'];
}
if (isset($_GET['act'])) {
    if ($_GET['act'] == 'remove') {
        removeCartItem($_GET['part'],$usrSession);
    }
}
if (isset($_POST['numItems'])) {
// Process the update code
$numItems = $_POST['numItems'];
$items = $_POST;
echo ("\n\n\n <!-- ");
print_r($_POST);
echo ("  --> \n\n\n");
    for ($x=0;$x < $numItems; $x++) {
        $itm = 'item'.($x+1);
        $quan = 'Qty'.($x+1);
        changeCartItem($items[$itm],$usrSession,$items[$quan]);
    }
}
?>

There is a lot in that code that doesn't make sense. (Not helped by the lack of

tags)

First of all, the implode function is being called using a variable ($value) that doesn't exist. (At least nowhere in the code you posted.)

And you are handling the check-boxes from the form incorrectly.
This is how you would typically handle an array of checkboxes, like your numItems boxes:
[code=php]
$boxes = $_POST['numItems'];
foreach($boxes as $_name => $_value) {
  echo "$_name = $_value<br />";
  // Or whatever you want to use them for.
}
This article has been dead for over six months. Start a new discussion instead.