为了账号安全,请及时绑定邮箱和手机立即绑定

在我取消设置变量之前,我的多表单页面工作得很好。为什么?

在我取消设置变量之前,我的多表单页面工作得很好。为什么?

慕勒3428872 2023-09-11 16:49:38
我已经在多表单页面上工作了一段时间。我需要一些帮助来尝试理解为什么当我取消设置变量时,多表单页面无法正常工作。我在代码中放置了一条 echo 语句来跟踪变量值,甚至在页面刷新后变量仍然保留。从字面上看,我必须删除该站点的 cookie 才能取消设置该变量。这是代码:<?phpsession_start();// Start the sessionecho $_SESSION["formatPickleball"];$_SESSION["Pickleball"] = "";// Submit button is pressedif (isset($_POST['format1'])){    $_SESSION["formatPickleball"] = $_POST['member'];    $_SESSION["Pickleball"] = "hide";}if ($_SESSION["formatPickleball"] == "Captain") {$regCAP = "";// Submit button is pressedif (isset($_POST['submitCAP'])){$regCAP = "show";}$secondCAP = "";// Submit button is pressedif (isset($_POST['submit2'])){$secondCAP = "show";}$thirdCAP = "";// Submit button is pressedif (isset($_POST['submit3'])){$thirdCAP = "show";}} elseif ($_SESSION["formatPickleball"] == "Player") {$regPlay = "";// Submit button is pressedif (isset($_POST['submitPlay'])){$regPlay = "show";} }?><html><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"><script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.jquery.min.js"></script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.min.css">    <script type="text/javascript"></script><body><div id="mainForm">    <h4>Are you a Captain or a Player on a Team?</h4><form method='POST'>    <input type="radio" name="member" value="Captain">Captain    <input type="radio" name="member" value="Player">Player<br>    <input type="submit" name="format1" value="Select">     </form></div>当我添加 $_SESSION["formatPickleball"] = ""; 到php代码的顶部,多表单无法正常工作。我有两个问题 1) 如何在不删除 cookie 的情况下取消设置变量?2)这是用 PHP 编写此代码的最有效方法吗?
查看完整描述

3 回答

?
千万里不及你

TA贡献1784条经验 获得超9个赞

存储在会话中的值必须在脚本执行结束时被丢弃。

  1. 销毁 $_SESSION 使用 unset($ _ SESSION) 和

  2. 然后使用销毁会话本身 session_destroy();


查看完整回答
反对 回复 2023-09-11
?
不负相思意

TA贡献1777条经验 获得超10个赞

一旦 if 语句完成,我就可以通过使用窗口弹出窗口来清除变量。


if ($Num_CTeams > 1 && $_SESSION["Pickleball"] !="") {

    echo '<script language="javascript">';

    echo 'alert("Sorry, Captains can only captain up to two teams ONLY.")';

    echo '</script>';

    $_SESSION["formatPickleball"] = "";


查看完整回答
反对 回复 2023-09-11
?
素胚勾勒不出你

TA贡献1827条经验 获得超9个赞

<?php

session_start();


echo $_SESSION["formatPickleball"];

$_SESSION["Pickleball"] = "";


if (isset($_POST['format1']) && $_POST['format1'] && isset($_POST['member']) && $_POST['member']) {

    $_SESSION["formatPickleball"] = $_POST['member'];

    $_SESSION["Pickleball"] = "hide";

}


if ($_SESSION["formatPickleball"] == "Captain") {

    $regCAP = isset($_POST['submitCAP']) && $_POST['submitCAP'] ? "show": "";

    $secondCAP = isset($_POST['submit2']) && $_POST['submit2'] ? "show": "";

    $thirdCAP = isset($_POST['submit3']) && $_POST['submit3'] ? "show": "";

if ($_SESSION["formatPickleball"] == "Player") {

    $regPlay =  isset($_POST['submitPlay']) && $_POST['submitPlay'] ? "show" : "";

}


查看完整回答
反对 回复 2023-09-11
  • 3 回答
  • 0 关注
  • 106 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信