【问题标题】:Storing Form Data as a Session Variable PHP将表单数据存储为会话变量 PHP
【发布时间】:2021-02-01 20:32:29
【问题描述】:

我查看了Storing Form Data as a Session Variable,但不能完全让它对我有用,而且我的代码几乎相同。任何建议表示赞赏!

<?php
session_start();    
?>  

    <form action="checkout.php" method="post">
    <div>
        Customer ID: <input type="text" name="customer_id" />
    </div>
    <input type="submit" name="checkout" value="Checkout" />
    </form>
    ';

<?php 
    if (isset($_POST['checkout'])) { 
       $_SESSION['customer_id'] = $_POST['customer_id'];
    } 
?>

上面的代码不起作用,但下面的代码可以。我在文本框中输入了相同的数字。

<?php
    $_SESSION['customer_id'] = 1024;
?>

【问题讨论】:

  • 变量名也区分大小写,$_session 也不例外
  • 你应该将会话 $_SESSION 大写,因为它是全局的
  • 为您的困惑道歉,但它也不适用于所有大写字母。我也这样测试过。
  • 试试if(isset($_POST['customer_id'])) {

标签: php forms variables session


【解决方案1】:

https://www.php.net/manual/ru/language.variables.superglobals.php 使用$_SESSION 而不是$_session 注意大小写,全局变量都是大写的。

【讨论】:

  • 为您的困惑道歉,但它也不适用于所有大写字母。我也这样测试过。
猜你喜欢
  • 2011-04-17
  • 1970-01-01
  • 1970-01-01
  • 2019-01-31
  • 1970-01-01
  • 1970-01-01
  • 2015-10-09
  • 2013-10-11
  • 1970-01-01
相关资源
最近更新 更多