2

我一直在一页中显示两条会话消息,评级。每次刷新都会显示一条消息,显示好恶。提交评分表后显示的另一条消息,问题是一旦我提交评分表,显示评分的消息就不会显示。为什么会这样???我不能在一个页面中使用两个会话吗?谢谢

编码

<?php
if(!empty($_SESSION['error_msg'])){?>
    <div style="text-align: center"><?php echo $_SESSION['error_msg'];?></div>

    <?
    session_unset($_SESSION['error_msg']);
}
?>

if(!empty($_SESSION['rate_msg'])){
            echo $_SESSION['rate_msg'];
            session_unset($_SESSION['rate_msg']);
        }
  ?>
  <form name="rating_form" action="" method="post">
      <input type="hidden" name="g_id" value="<?php echo $ratings['gallery_id'];?>"/>
      <input type="hidden" name="g_image" value="<?php echo $ratings['gallery_image'];?>"/>
      <div style="text-align: center">
          <input type="radio" name="rating" value="Hot" onclick="document.rating_form.submit();">Hot</input>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <input type="radio" name="rating" value="Not" onclick="document.rating_form.submit();">Not</input>
      </div>
  </form>
4

5 回答 5

1

抱歉,我认为我的代码有点混乱我的实际代码看起来像这样

<div class="top_model">
                    <h1>Model Ratings</h1>
                        <?php
                           if(!empty($_SESSION['error_msg'])){?>
                                <div style="text-align: center"><?php echo $_SESSION['error_msg'];?></div>

                                <?
                                session_unset($_SESSION['error_msg']);
                            }
                        ?>
                      <ul class="homemodel_thumbs">
                          <div style="text-align: right">

                              </div> 

                          <?php
                            if(!empty($ratingArr)){
                                foreach($ratingArr as $ratings){

?>

                          <li><img src="<?php echo base_url();?>images/gallery/large/<?php echo $ratings['gallery_image'];?>" alt="<?php echo $ratings['gallery_image'];?>" class="center_image"/>
                              <p>&nbsp;&nbsp;</p>
                              <?php
                              if(!empty($_SESSION['rate_msg'])){
                                        echo $_SESSION['rate_msg'];
                                        //session_unset($_SESSION['rate_msg']);
                                    }
                              ?>
                              <form name="rating_form" action="" method="post">
                                  <input type="hidden" name="g_id" value="<?php echo $ratings['gallery_id'];?>"/>
                                  <input type="hidden" name="g_image" value="<?php echo $ratings['gallery_image'];?>"/>
                                  <div style="text-align: center">
                                      <input type="radio" name="rating" value="Hot" onclick="document.rating_form.submit();">Hot</input>
                                      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                      <input type="radio" name="rating" value="Not" onclick="document.rating_form.submit();">Not</input>
                                  </div>
                              </form>

                          </li>    

                             <?php    
                                }
                            }
                            ?>
                       </ul>
于 2012-06-15T07:38:49.520 回答
1

这个问题就解决了。在两个会话消息中,一个我使用了 php 会话,而另一个我使用了代码点火器会话。抱歉,如果我没有提到我正在使用 ci。无论如何感谢大家的帮助:)

于 2012-06-20T04:50:15.033 回答
0

您在显示后取消设置您的评级消息:

session_unset($_SESSION['rate_msg']);

这意味着在您发回表单后它不可用,除非您再次重新填充它。

删除它,我怀疑它会起作用。

于 2012-06-15T07:11:43.100 回答
0

你有多余的?>

<?php
     if(!empty($_SESSION['error_msg'])){?>
        <div style="text-align: center"><?php echo $_SESSION['error_msg'];?></div>
<?
     session_unset($_SESSION['error_msg']);
     }

    if(!empty($_SESSION['rate_msg']))
    {
        echo $_SESSION['rate_msg'];
        session_unset($_SESSION['rate_msg']);
    }
?>
于 2012-06-15T07:18:46.797 回答
0

您没有为最后一条语句打开 php 标记,(或不必要地关闭它)它被视为 html

<?php
if(!empty($_SESSION['error_msg'])){?>
    <div style="text-align: center"><?php echo $_SESSION['error_msg'];?></div>

    <?php
    session_unset($_SESSION['error_msg']);
}

?>

if(!empty($_SESSION['rate_msg'])){
            echo $_SESSION['rate_msg'];
            session_unset($_SESSION['rate_msg']);
        }
  ?>

编辑

<?php
// < HERE IS PHP >
if(!empty($_SESSION['error_msg'])){?>
    <div style="text-align: center"><?php echo $_SESSION['error_msg'];?></div>
    <!-- HERE IS HTML -->
    <?
    // < HERE IS PHP >
    session_unset($_SESSION['error_msg']);
}
?> <!-- CLOSED PHP - NOW IT'S HTML - YOU SHOULD REMOVE IT -->

<!-- THIS IS NOT EXECUTED - BECAUSE IT'S HTML NOW -->
if(!empty($_SESSION['rate_msg'])){
            echo $_SESSION['rate_msg'];
            session_unset($_SESSION['rate_msg']);
        }
  ?> <!-- THIS IS NOT PHP TAG BECASUE THERE IS NOT OPEN TAG -->
  <form name="rating_form" action="" method="post">
      <input type="hidden" name="g_id" value="<?php echo $ratings['gallery_id'];?>"/>
      <input type="hidden" name="g_image" value="<?php echo $ratings['gallery_image'];?>"/>
      <div style="text-align: center">
          <input type="radio" name="rating" value="Hot" onclick="document.rating_form.submit();">Hot</input>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <input type="radio" name="rating" value="Not" onclick="document.rating_form.submit();">Not</input>
      </div>
  </form>
于 2012-06-15T07:21:53.533 回答