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?

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.