phpretard Posted April 18, 2008 Share Posted April 18, 2008 I have tried quite a few time and can't quite make it work. $file keeps showing up instead of "$files" 's posted value. Array ( [$file] => Array ( [0] => 4 x 6 [1] => 10 [2] => 5 x 7 [3] => 20 [4] => 8 x 10 [5] => 30) ) if(isset($_POST['order_photo'])) { $file = array(); $file[0] = $_POST['S46']; $file[1] = $_POST['QU46']; $file[2] = $_POST['S57']; $file[3] = $_POST['QU57']; $file[4] = $_POST['S810']; $file[5] = $_POST['QU810']; $file[6] = $_POST['file']; $file[7] = $_POST['picture']; $_SESSION['$file']=$file; print_r($_SESSION); } Actually...is $file even naming the Session Var? Quote Link to comment Share on other sites More sharing options...
zenag Posted April 18, 2008 Share Posted April 18, 2008 print_r($_SESSION['$file']); Quote Link to comment Share on other sites More sharing options...
Fadion Posted April 18, 2008 Share Posted April 18, 2008 U need to have a variable inside double quotes to get its value. So $_SESSION["$file"] should give the real variable value to the session variable. But logically the way u are assigning an array to the session variable wont work. U need to loop throught the values of the array. Ex: <?php $file = array(); $file[] = $_POST['S46']; $file[] = $_POST['QU46']; $file[] = $_POST['S57']; foreach($file as $val){ $_SESSION["$val"] = $val; } ?> Thats basically what u want to do, even if it makes no sense to have both the session name and value the same. Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 I have tried something similar and this is what I get. Parse error: syntax error, unexpected $end on line 48 I get the same with the code you put up. if(isset($_POST['order_photo'])) { $file = array(); $file[] = $_POST['S46']; $file[] = $_POST['QU46']; $file[] = $_POST['S57']; $file[] = $_POST['QU57']; $file[] = $_POST['S810']; $file[] = $_POST['QU810']; $file[] = $_POST['file']; $file[] = $_POST['picture']; foreach($file as $val){ $_SESSION["$val"] = $val; print_r($_SESSION['$val']); } Could you perhapse elaberate just a little? Quote Link to comment Share on other sites More sharing options...
Fadion Posted April 18, 2008 Share Posted April 18, 2008 U forgot to close the foreach loop. foreach($file as $val){ $_SESSION["$val"] = $val; } Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 18, 2008 Share Posted April 18, 2008 What, exactly, are you trying to accomplish? Please explain in English, no code. Ken Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 Thank Bjesus someone want english vs code... I am tring to create multiple sessions with different values. The values are populated by different forms. Then I would like to print all the session variables on one page. Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 With each form posted > create a new session with a unique name which is $file Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 comprehendo? Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 No more Help? Quote Link to comment Share on other sites More sharing options...
haku Posted April 18, 2008 Share Posted April 18, 2008 foreach($file as $val){ $_SESSION[$val] = $val; print_r($_SESSION[$val); } if $val = "a" you will end up with $_SESSION['a'] having a value of 'a' Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 That worked well. Thank you!!! Do you know why this doesn't work? foreach ($_SESSION){ echo"stuff"; } syntax error, unexpected ')' Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 18, 2008 Share Posted April 18, 2008 Incorrect foreach syntax. Check the manual Ken Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.