im tring to make a page that will store the passed variable from a form into an array.. one by one.. i mean, i type in a value, i submit the form, and $id[0] gets it, then i type another value, submit it, then it becomes $id[1] and so on up to $id[4]..

this is what i've got so far..

if(isset($model[$i]))
{
$i++;
}

$model = array( $i => '$model' );

and i hav to echo each value to a text field after all 5 values have been filled..
harhar!!! i cant find my code!!!! Thanks!!!

    Your post doesn't make a lot of sense. It's already in an array. $GET and $POST are both arrays.

      so i can just submit the value over and over and all the succeeding values will fall in? $id[0] up to $id[4]? im using get.. it didnt happen.. my code is all messed up i guess..

        Hi,

        if you want to do this step by step do something like this:

        //on to of the script
        session_start();
        if (!isset($_SESSION['values'])) {
          $_SESSION['values'] = array();
        }
        
        if (isset($_POST['inputname'])) {
          $_SESSION['values'][] = $_POST['inputname'];
        }
        
        // if you want to store that to a file
        $fp = fopen("thefile.txt","w+");
        if ($fp) {
          fwrite($fp,implode("\r\n",$_SESSION['values']));
          fclose($fp);
        }
        

        use \n instead of \r\n if you want to have a UNIX text file.
        This code lacks some checks (e.g. if the array contains data at all before writing to the file).

        If you expect exactly five values to be submitted I'd suggest to create a form that already has five input fields. Or have a field where a user can submit a numeric value and then show the form again with that number of input fields.

        Thomas

          Write a Reply...