0

按下 index.php 上的提交按钮后,index2.php 中没有显示输出

    //index1.php
   <form action="index2.php" name="firstSubmit" method="POST">
<table border="0" cellspacing="10">
    <tr>
        <td>Full Name: </td>
        <td><input name="fullname" id="name" type="text" size="20" maxlength="80"></td>
    </tr>
    <tr>
        <td>Title:</td>
        <td><input name="title" id="title" type="text" size="20" maxlength="80"></td>
    </tr>
    <tr>
        <td>Company:</td>
        <td><input name="company" id="company" type="text" size="20" maxlength="80"></td>
    </tr>
    <tr>
        <td>Course:</td>
        <td>PHP Basics</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td colspan="2"><input type="Submit" name="submit" value="Proceed"></td>
    </tr>
</table>
</form>

//index2.php
<?php session_start();
$_SESSION['fullname']       = $_POST['fullname'];
$_SESSION['title']          = $_POST['title'];
$_SESSION['company']        = $_POST['company'];
$_SESSION['time']           = $_POST['time'];
?> 

<form action="certificate.php" name="certificateSubmit" method="POST">
<table border="0" cellspacing="10">
    <tr>
        <td>Full Name: </td>
        <td><?php echo  $_SESSION['fullname']; ?></td>
    </tr>
    <tr>
        <td>Title:</td>
        <td><?php echo  $_SESSION['title']; ?></td>
    </tr>
    <tr>
        <td>Company:</td>
        <td><?php echo  $_SESSION['company']; ?></td>
    </tr>
    <tr>
        <td>Course:</td>
        <td>PHP Basics</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td colspan="2"><input type="Submit" name="submit" value="Generate Certificate &gt; &gt;"></td>
    </tr>
</table>
</form>

---------我刚刚更新了脚本。这次没有出现关于 session_start() 的警告,但是按下进程按钮后没有结果显示+----

4

2 回答 2

1

确保 index.php 和 index2.php 在开头之前<?php或结尾之后没有空格?>。此外,许多人已将其作为最佳实践采用的提示:不要?>在任何文件的底部包含结束标记;当 PHP 遇到文件末尾时,它会自动添加它。我提到它是因为这也有助于避免空格问题。

根据要求,这是一个基本正确会话使用的示例(尽管这里的问题实际上与调试包含的文件和空格等有关,以确保在session_start调用之前没有输出): http://www.php。网络/手册/en/session.examples.basic.php

于 2013-02-25T02:55:26.263 回答
1

The problem is that you have a php comment before the opening <?php. Take away the //index2.php and you should be good to go.

Unless, of course, you just added that for this example! If that is the case, then just check that the <?php is the absolute first character in the file.

于 2013-02-25T03:10:15.323 回答