简体   繁体   English

将表单数据存储为会话变量 PHP

[英]Storing Form Data as a Session Variable PHP

I reviewed Storing Form Data as a Session Variable but can't quite get it working for me and I have nearly the same code.我回顾了将表单数据存储为会话变量,但不能完全让它为我工作,我有几乎相同的代码。 Any suggestions are appreciated!任何建议表示赞赏!

<?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'];
    } 
?>

The code above doesn't work, but the below does.上面的代码不起作用,但下面的代码起作用。 I am typing the same number in the text box.我在文本框中输入相同的数字。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM