doumengxue7371
doumengxue7371
2015-12-14 06:50

PHP在$ _SESSION中组合变量但在调用时接收未定义的变量

I have this bit of code in my script, the SESSION was started at the top of the page - just for your info.

$_SESSION['PlanType'] // set in form
$_SESSION['ReceipientNum'] // Set Earlier in Form Handler
if ($_POST['action'] == 'AddAnother') {  // If Add Another button was selected
    $_SESSION[${'PlanType'.$_SESSION['ReceipientNum']}] = $_SESSION['PlanType'];
    echo $_SESSION[${'PlanType'.$_SESSION['ReceipientNum']}]; // this was line 372
    exit;

    } else if ($_POST['action'] == 'Review') {

        //Do stuff
    }

When i try and echo the variable I am getting -

Notice: Undefined variable: PlanType1 in .../shipping.php on line 372

But then follows with the correct value that was set. Has this got something to do with the {} within the $_SESSION?

Cheers in adavance

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongshan1036 dongshan1036 6年前

    try this:

    ${'PlanType'.$_SESSION['ReceipientNum']}='';
    $_SESSION[${'PlanType'.$_SESSION['ReceipientNum']}] = $_SESSION['PlanType'];
        echo $_SESSION[${'PlanType'.$_SESSION['ReceipientNum']}]; // this was line 372
    
    点赞 评论 复制链接分享

相关推荐