【问题标题】:How to store entire $_POST variable in the session如何在会话中存储整个 $_POST 变量
【发布时间】:2013-11-08 07:43:15
【问题描述】:

我有下拉选择,当我单击提交按钮时,它会根据下拉列表的值显示记录。它工作正常,但是当我刷新 app_list2.php 时它什么也没显示。我想保留 app_list2.php 中显示的记录。如何在会话中存储所有 $_POST 值?

    <?php
    $mysqli = new mysqli("localhost", "root", "", "app");
    if(isset($_POST['submit'])){
    $drop = $_POST['drop_1'];
    $tier_two = $_POST['tier_two'];

    $where = "WHERE app_cn='$drop' AND app_plan_no='$tier_two'";

$result1 = $mysqli->query("
    SELECT *, SUM(unit_cost*quantity) AS total_amount, SUM(unit_cost*1st_quarter) AS 1st_quarter_total, SUM(unit_cost*2nd_quarter) AS 2nd_quarter_total, SUM(unit_cost*3rd_quarter) AS 3rd_quarter_total,
    SUM(unit_cost*4th_quarter) AS 4th_quarter_total, SUM((quantity)-(1st_q_qty_del+2nd_q_qty_del+3rd_q_qty_del+4th_q_qty_del)) AS balance
    FROM app 
    $where 
    GROUP BY counter ORDER BY counter
");
?>

<?php
echo'<table id="tfhover" cellspacing="0" class="tablesorter" style="text-transform:uppercase;">
        <thead>
            <tr>
        <th>Item</th>
        <th>Description</th>
        <th>Fund Source</th>
        <th>Unit</th>
        <th>Unit Cost</th>
    </tr>
        </thead>';
        echo'<tbody>';
$i=1;
while($row = $result1->fetch_assoc()){
if($row['app_cn'] != '')
 {
 echo'<tr>
    <td>'.$row['item_name'].'</td>
        <td>'.$row['item_description'].'</td>
    <td>'.$row['fund_source'].'</td>
        <td>'.$row['unit'].'</td>
        <td>'.number_format($row['unit_cost'], 2, '.', ',').'</td>
       </tr>';
    }
        }
    echo "</tbody></table>";
}
?>

【问题讨论】:

  • 检查错误,似乎是 php 错误。并清理您的查询字段
  • 没有错误,我想是因为它没有确定记录的 id 吗?
  • 它是因为在刷新时,您将丢失对已发布值的跟踪,因此不会出现任何内容
  • @leobali 是的,即使我刷新页面,我如何才能获得发布的价值?
  • 将所有帖子值存储到会话

标签: php jquery mysql mysqli


【解决方案1】:

试试这个代码

<?php

    ob_start();
    session_start();
        $mysqli = new mysqli("localhost", "root", "", "app");



    if(isset($_POST['submit'])){

    //unset the session value 
    $_SESSION['content'] = '';

    $drop = $_POST['drop_1'];
    $tier_two = $_POST['tier_two'];

    $where = "WHERE app_cn='$drop' AND app_plan_no='$tier_two'";

$result1 = $mysqli->query("
    SELECT *, SUM(unit_cost*quantity) AS total_amount, SUM(unit_cost*1st_quarter) AS 1st_quarter_total, SUM(unit_cost*2nd_quarter) AS 2nd_quarter_total, SUM(unit_cost*3rd_quarter) AS 3rd_quarter_total,
    SUM(unit_cost*4th_quarter) AS 4th_quarter_total, SUM((quantity)-(1st_q_qty_del+2nd_q_qty_del+3rd_q_qty_del+4th_q_qty_del)) AS balance
    FROM app 
    $where 
    GROUP BY counter ORDER BY counter
");
?>

<?php
echo'<table id="tfhover" cellspacing="0" class="tablesorter" style="text-transform:uppercase;">
        <thead>
            <tr>
        <th>Item</th>
        <th>Description</th>
        <th>Fund Source</th>
        <th>Unit</th>
        <th>Unit Cost</th>
    </tr>
        </thead>';
        echo'<tbody>';
$i=1;
while($row = $result1->fetch_assoc()){
if($row['app_cn'] != '')
 {
 echo'<tr>
    <td>'.$row['item_name'].'</td>
        <td>'.$row['item_description'].'</td>
    <td>'.$row['fund_source'].'</td>
        <td>'.$row['unit'].'</td>
        <td>'.number_format($row['unit_cost'], 2, '.', ',').'</td>
       </tr>';
    }
        }
    echo "</tbody></table>";

    $sPageContent = ob_get_clean();
    $_SESSION['content']    =   $sPageContent;

}else{

    if (isset($_SESSION['content'])){
        echo $_SESSION['content'];
    }


}
?>

【讨论】:

  • 在尝试此代码之前尝试清除缓存,并在刷新之前在第一次显示上调试会话值..页面内容是否存储在该值中??
  • 抱歉回复晚了,我试过这段代码。当我单击提交按钮时,app_list.php 什么也不显示。但是当我刷新页面时,它会显示记录。这是为什么呢?
猜你喜欢
  • 2011-01-26
  • 2020-11-06
  • 1970-01-01
  • 1970-01-01
  • 2020-03-12
  • 1970-01-01
  • 2012-05-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多