Jump to content

[SOLVED] Can you name a session variable with a posted variable?


phpretard

Recommended Posts

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?

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.

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.