Hello All,
It's been a few days but after a half a day going through books and websites I still can't get this to work. I haven't used a lot of arrays in the past and dealt with even less indexed arrays. I'm trying to post a form and have the data added to an array. The array is created on another page and stored in a session. This is working fine as I add data to it on the other page and I can see it when I echo it on the new page. Here's what I'm trying to do:

<?php
$userp = $_POST['userp'];
$formgo = $_POST['formgo'];

if ($formgo == "yes"){
$showvarc = $_SESSION['showvarc'];

for ($i = 0; $i < count($userp); ++$i) {
array_push ($showvarc,$userp[$i]);
  }

$_SESSION['showvarc'] = $showvarc;
}
?>

<form name="myform" method="post" action="http://www.fassttech.com/otc/teamsearch.php" enctype="multipart/form-data">

Value 1: <input type="checkbox" name="userp[]" value="1" /><br />
Value 1: <input type="checkbox" name="userp[]" value="1" /><br />
Value 1: <input type="checkbox" name="userp[]" value="1" /><br />
Value 1: <input type="checkbox" name="userp[]" value="1" /><br />
<input type="hidden" name="formgo" value="yes" /><input type="submit" name="submit" /></form>

Hopefully I'm not completely off the reservation. Thanks in advance.

    <?php
    session_start();
    $_SESSION['showvarc'] = array();
    ?>
    
    <form action="" method="post">
    Value 1: <input type="checkbox" name="userp[]" value="1" /><br />
    Value 2: <input type="checkbox" name="userp[]" value="2" /><br />
    Value 3: <input type="checkbox" name="userp[]" value="3" /><br />
    Value 4: <input type="checkbox" name="userp[]" value="4" /><br />
    <input type="submit" name="submit" />
    </form>
    
    <?php
    if (isset($_POST['submit']))
    {
    	if (isset($_POST['userp'])) {array_push($_SESSION['showvarc'], $_POST['userp']);}
    	else {echo 'you didi not check anything';}
    }
    ?>
    

      Thanks for the reply. It doesn't seem to be working but I'll keep trying.

        Well, you haven't actually said what the problem is.

          Resolved. Sorry. The problem was that the data being posted by the form was not being added to the existing array "showvarc". I was trying to run a loop on the array created when the form was submitted and one by one add those to the existing array, I'm still not sure why that didn't work but array_merge did and serves my purpose just fine this time. Thanks for trying to help.

            Write a Reply...