从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
我正在尝试从示例代码计数($ result)创建$ _SESSION。 我已经像这样对变量进行了decalred: p>
$ result = array();
$ result [] = $ boxdest;
code> pre> \ n
这在我运行它的页面上工作正常但我需要将值传递给在php mail()函数中使用的页面。 我试过了 p>
$ _ SESSION ['result'] = $ result;
code> pre>
但我得到的只是 资源ID#40。 如何将此变量传递给另一个页面。 完整的代码示例: http://sandbox.onlinephpfunctions.com/code/ba0a34774e30c93edfdf02f531bb199c681021e3 非常感谢 p>
div>
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.
U can't store any Resource
in PHP session
https://*.com/a/42389037/5361130
http://php.net/manual/en/function.serialize.php
EDIT
if your $result
is result of function like mysqli_query
or something like this, use mysqli_num_rows
to get number of rows not count
http://php.net/manual/en/mysqli-result.num-rows.php
$result = mysqli_num_rows($boxdest)
or
$_SESSION['result'] = mysqli_num_rows($boxdest)