Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP会话的新特性_Php_Html_Session - Fatal编程技术网

PHP会话的新特性

PHP会话的新特性,php,html,session,Php,Html,Session,我正在努力掌握会话,因为它是PHP的一部分,我不太擅长。你能帮我解释一下我这两页的内容吗?它给出了一个未定义的索引,我不知道为什么 谢谢 文件1 <strong>Test Form</strong> <form action="test2.php" method"post"> <input type="text" name="picturenum"/> <input type="submit" name="Su

我正在努力掌握会话,因为它是PHP的一部分,我不太擅长。你能帮我解释一下我这两页的内容吗?它给出了一个未定义的索引,我不知道为什么

谢谢

文件1

    <strong>Test Form</strong>
    <form action="test2.php" method"post">
    <input type="text" name="picturenum"/>
    <input type="submit" name="Submit" value="Submit!" />
    </form>

    <?php 

     // starting the session
     session_start();


     if (isset($_POST['Submit'])) { 
     $_SESSION['picturenum'] = $_POST['picturenum'];
     } 


?> 
测试表
文件2

<?php

session_start(); 

echo $_SESSION['picturenum'];

?>

会话\u start()
必须放在页面顶部:

<?php
session_start();
// Opening <html>, etc goes below
?>  
<strong>Test Form</strong>
    <form action="test2.php" method"post">
    <input type="text" name="picturenum"/>
    <input type="submit" name="Submit" value="Submit!" />
    </form>

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

测试表

据我所知,您正在第一个文件中的表单之后启动会话。规则是:您应该在任何
echo
或任何HTML输出之前启动会话,甚至在空格之前。因此,基本上,
session\u start()
应该是
之后的第一行:

表单(teste1.php)

<?php
session_start();
// Opening <html>, etc goes below
?>  
<strong>Test Form</strong>
<form action="test2.php" method"post">
<input type="text" name="picturenum"/> <!-- make sure you type something here -->
<input type="submit" name="Submit" value="Submit!" />
</form>

测试表
文件2(test2.php)



这是您的
test2.php
,是
文件1
还是
文件2
?在调用session\u start()之前,不允许输出任何内容。重新排列代码,使其位于文件的顶部,在任何输出之前。它在eroor上。我正在获取详细索引:picturenum在C:\wamp\www\xyz\test2.php的第4行。如果没有看到itI周围的所有代码,很难判断为什么会发生这种情况。我必须假设它引用的是POST变量,这意味着它不是由您的表单发送的。这可能是因为该字段为空,或者您的字段名称与代码中的字段名称不同。在html中键入表单标记上的它应该是
method=“post”
。我进入下一页的方式是通过表单操作,对吗?
<?php
if (isset($_POST['picturenum'])) { 
$_SESSION['picturenum'] = $_POST['picturenum'];
echo $_SESSION['picturenum'];
}else{
echo "something wrong with the POST";
}
?>