如何将标签传递到POST

时间:2019-03-30 15:10:55

标签: php variables session post

我当前正在使用会话变量填充标签,但是我需要稍后使用标签数据(将其发送到另一个标签),或者创建一个新的会话来这样做。但是,当我尝试访问第一个标签时,或者ive设置其的会话告诉我未设置。因此,我假设第一个标签中的数据正在显示,但实际上并未显示?

//这是即时消息创建第一个标签的方式

<?php

  include_once "dbcon.php";

  //PERFORMING CHECK IF ALL REQUIRED SESSION VARIABLES ARE SET
  if (isset($_SESSION['s_score1'], $_SESSION['s_score2'], $_SESSION['t_team1'], $_SESSION['t_team2'])) {
    $team1 = $_SESSION['t_team1'];
    $team2 = $_SESSION['t_team2'];
    $score1 = $_SESSION['s_score1'];
    $score2 = $_SESSION['s_score2'];

    if ($score1 == $score2) {
      header("Location: tables.php?table=draw"); //CHECKS IF MATCH IS A DRAW, CANNOT BE A DRAW
      exit();
    }else {
      if ($score1 > $score2){
        echo $_SESSION['t_team1'];
      }else {
        echo $_SESSION['t_team2'];

      }
    }
  }else {
  echo "-";
}
?>

//这是即时消息的打印方式

<label name="round2-team1" class="round2-teams">
          <?php include_once "action/winner-script.php";?>
        </label>

当我尝试在上方使用此标签,使用它创建会话变量或将其移动到新标签时,即使我可以在页面上看到它,也不可能将其移到新标签中?

<?php

  include_once "dbcon.php";

  //PERFORMING CHECK IF ALL REQUIRED SESSION VARIABLES ARE SET
  if (isset($_SESSION['s_score9'], $_SESSION['s_score10'], $_SESSION['t_team9'], $_SESSION['t_team10'])) {
    $team1 = $_SESSION['t_team9'];
    $team2 = $_SESSION['t_team10'];
    $score1 = $_SESSION['s_score9'];
    $score2 = $_SESSION['s_score10'];

    if ($score1 == $score2) {
      header("Location: tables.php?table=draw"); //CHECKS IF MATCH IS A DRAW, CANNOT BE A DRAW
      exit();
    }else {
      if ($score1 > $score2){
        echo $_SESSION['t_team9'];
      }else {
        echo $_SESSION['t_team10'];

      }
    }
  }else {
  echo "-";
}
?>

这是脚本,这里我将显示在页面上的两个标签,确定赢家,然后在同一页面上的另一个标签中显示赢得比赛的会话变量。但是,当我尝试使用

<?php
  if (isset($_SESSION['t_team9'])) {
 echo $_SESSION['t_team9'];
}else {
  echo "somethings wrong";
}
  ?>

在我标签所在的页面上的任何地方,我只是收到错误消息而已

尝试修复:

<?php

  include_once "dbcon.php";

  //PERFORMING CHECK IF ALL REQUIRED SESSION VARIABLES ARE SET
  if (isset($_SESSION['s_score13'], $_SESSION['s_score14'], $_SESSION['result'], $_SESSION['result2'])) {
    $team1 = $_SESSION['result'];
    $team2 = $_SESSION['result2'];
    $score1 = $_SESSION['s_score13'];
    $score2 = $_SESSION['s_score14'];

    if ($score1 == $score2) {
      header("Location: tables.php?table=draw"); //CHECKS IF MATCH IS A DRAW, CANNOT BE A DRAW
      exit();
    }else {
      if ($score1 > $score2){
        $team1 = $_SESSION['result'];
        $_SESSION['result5'] = $team1;
      }else {
        $team2 = $_SESSION['result2'];
        $_SESSION['result5'] = $team2;

      }
    }
  }else {
  echo "-";
}
?>

1 个答案:

答案 0 :(得分:0)

您需要在内部回显$ _SESSION。
而且您不需要包括创建会话的页面。
并检查您要使用会话的每个页面顶部是否都有session_start()。因此,在您拥有<label>的页面上
另外,我建议您为结果创建一个会话。像$_SESSION['Result'];
$_SESSION['Result']是基于匹配结果的。像这样

if ($score1 > $score2){
     $team1 = $_SESSION['t_team1'];
     $_SESSION['Result'] = $team1;
     header('Location: to_your_result_page);
}
else if($score2 > $score1) {
     $team2 = $_SESSION['t_team2'];
     $_SESSION['Result'] = $team2;
     header('Location: to_your_resultpage);
}


并在页面中显示结果:

<label name="round2-team1" class="round2-teams">
     <?php echo $_SESSION['Result'] ?>
</label>