RE: [PHP] Array in a $_session

From: Date: Tue, 17 Jun 2003 10:37:55 +0000
Subject: RE: [PHP] Array in a $_session
Groups: php.general 
Request: Send a blank email to php-general+get-151812@lists.php.net to get a copy of this message
Dear all, Finnaly managed it (it's working! :>)... But can you check if this is the way? (step1.php) <? $_REQUEST["submit"]=isset($_REQUEST["submit"])?$_REQUEST["submit"]:""; if($_REQUEST['submit']!="") { session_start(); $_SESSION['test1'] = array(); $_SESSION['test1'] = $_POST['test1']; session_write_close(); header("Location: step4.php"); } ?> <form name="form1" method=post id=form1 enctype=multipart/form-data action=<?=$_SERVER['PHP_SELF']?>> <? for ($i=1; $i<=4; $i++) { ?> <table width="50%" border="0" cellpadding="5"> <tr>Reiziger <? echo $i; ?> <td>Voorletters</td> </tr> <tr> <td><? echo "<input type=\"text\" name=\"test1[$i]\" size=\"6\"><br>"; ?></td> </tr> </table> <? } ?> <input type=submit name=submit value=submit> </form> (STEP4.PHP) <?php session_start(); $_SESSION['test1'] = array_merge($_SESSION['test1'], $_POST['test1']); foreach($_SESSION['test1'] as $test1) echo $test1, '<br>'; ?> Regards, Frank >> -----Original Message----- >> From: fkeessen@planet.nl [mailto:fkeessen@planet.nl] >> Sent: 17 June 2003 07:48 >> >> Maybe you can make it a little bit clear for me? >> >> >You have not defined $i, so what did you expect to see here? >> >> >> session_start(); >> >> $aantalpers=$_SESSION["aantalpers"]; >> >> $test1 = $_SESSION['test1'][$i]; >> > >> >> So is it going to be: $test1[$i ]= $_SESSION['test1'][$i]; ??? > >No. This is worse than before. You still have not defined what $i is -- it has no value, it is >unset, it is equivalent to NULL. Therefore, $_SESSION['test1'][$i] is unlikely to return >anything meaningful. At least before you were putting unknown result into a known location ($test1) >-- but now you're trying to assign it to another non-meaningful place ($test1[$i], which is an >unknown quantity because $i is still undefined!). > >Cheers! > >Mike > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#151812) next »