douyao3895 2017-04-04 15:48
浏览 54
已采纳

从count变量创建php $ _SESSION

I am trying to create a $_SESSION from example code count($result). I have decalred the variable like thus:

$result = array();
$result[] = $boxdest;

This is working fine on the page where I run it but I need to pass the value to a page to use in php mail() function. I have tried

$_SESSION['result'] = $result;

But all I get is Resource id #40. How do I pass this variable to another page. Full code example here: http://sandbox.onlinephpfunctions.com/code/ba0a34774e30c93edfdf02f531bb199c681021e3 Many thanks

  • 写回答

2条回答 默认 最新

  • dotn30471 2017-04-04 16:56
    关注

    This is more of a critique of the code rather than a solution to the problem:

    $_SESSION['result'] = []; //Clear it in case there's an old value here.
    if (isset($_POST['boxdest']) && is_array($_POST['boxdest']) && !empty($_POST['boxdest'])) { //Merged condition
        $destroydata = explode(',', $_POST['boxdest'][0]); //Split was deprecated
        $result = array_filter($destroydata);
        if (empty($result) { 
               $boxdesterror = '<span style="font-weight:bold;font-size:12px;color: #ff0000;">' . 'BOX DESTRUCTION ERROR! ' . '</span>' . '<span style="font-weight:normal;color: #000;background-color:#ffa;">' . 'You must enter a box for destruction' . '</span>';
               echo "<script language=\"JavaScript\">
    ";
               echo 'alert("BOX DESTRUCTION ERROR:
    You must enter a box for destruction.");';
               echo "</script>";
               echo $boxdesterror;
        } else {
            echo 'You wish to destroy ' . count($result) . ' box(es): ' . '<div style="word-wrap:break-word;white-space: pre-wrap;overflow:auto !important;height: 100px; width: 250px; border: 1px solid #666; background-color: #fff; padding: 4px;">' . '<span style="font-weight:bold;color: #000;">' . implode(', ', $boxdest) . '</span>' . '</div>' . '<p />';
    
            $_SESSION['result'] = $result; //Did you really need both?
            $flag = 1;
         }
    }
    

    This should be the same results. I don't see why a resource would pop up from nowhere though.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题