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? Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/ Share on other sites More sharing options...
zenag Posted April 18, 2008 Share Posted April 18, 2008 print_r($_SESSION['$file']); Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520275 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. Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520281 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? Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520299 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; } Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520306 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 Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520309 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. Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520317 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 Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520330 Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 comprehendo? Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520338 Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 No more Help? Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520379 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' Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520382 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 ')' Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520408 Share on other sites More sharing options...
kenrbnsn Posted April 18, 2008 Share Posted April 18, 2008 Incorrect foreach syntax. Check the manual Ken Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520413 Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 Thank you Link to comment https://forums.phpfreaks.com/topic/101698-solved-can-you-name-a-session-variable-with-a-posted-variable/#findComment-520424 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.