会话无法在php脚本的第3个文件中运行

时间:2017-06-29 07:29:16

标签: php html oracle

我有3个文件(m1.php,m2.php,m3.php)

m1代码:

    <?php  session_start();     //starting the session ?>   
    <!DOCTYPE HTML>
    <html>
       <strong> Enter Phone Number: </strong>
         <form action="m2.php" method = "POST">
           <input type="text" name="ph"/>
           <input type="submit" name="submit" value="Submit" />
        </form>

     <?php 
       if (isset($_POST['submit'])) { 
       $_SESSION['ph'] = $_POST['ph'];
    } 
   ?> 
     </html>

m2代码:

     <?php session_start(); ?>
        <html>
         <body> Details of:
            <strong>
              <?php 
                echo $_POST['ph'];
                $_SESSION['phone'] = $_POST['ph'];
             ?>
            </strong>
         <?php
              $ph = $_SESSION['phone'];
              $link = oci_connect('hd','hd', 'localhost/mydb');
               if(!$link) {
                  $e = oci_error();
                  exit('Connection error    ' . $e['message']);
                }
               $q1 = "select CUST_ID from customer where CUST_PHONE = :bv_ph";
               $q1parse = oci_parse($link, $q1);
               oci_bind_by_name($q1parse, ':bv_ph', $phone);
               oci_execute($q1parse);
               oci_fetch($q1parse);
               $res = oci_result($q1parse, 'CUST_ID');
               if(!$res) {
                   echo "No Order found. New Order?";
               }
          ?>
        <?php
            if(isset($_POST['option']) && ($_POST['option']) == "Yes") {
                    header("Location: m3.php");
            }
            elseif(isset($_POST['option']) && ($_POST['option']) == "No") {
                    header("location: m1.php");
            }

            $q2 = "select A.ADDRESS, A.AREA from customer c 
              join customer_address ca on C.CUST_ID = CA.CUST_ID
              join address a on A.ADDRESS_ID = CA.ADDRESS_ID where C.CUST_ID = :id_bv";
            $q2parse = oci_parse($link, $q2);
            oci_bind_by_name($q2parse, ':id_bv', $res);
            oci_execute($q2parse);
            while($row = oci_fetch_array($q2parse)) {
                    echo "<tr><td>" . htmlentities($row["ADDRESS"]) . "</td>";
                    echo "<td>" . htmlentities($row["AREA"]) . "</td></tr>";
            }
             oci_free_statement($q2parse);
             oci_close($link);

         ?>

        <form action = "" method = "POST" >
            <input type = "radio" name = "option" value = "Yes" checked> Yes <br>
            <input type = "radio" name = "option" value ="No"> No <br>
            <input type = "submit" value = "submit">
        </form>
         <table border = "black">
            <tr> 
                <th> ADDRESS </th>
                <th> AREA </th>
            </tr>
         </table>
    </body>
</html>

m3代码:

<?php session_start(); ?>
<!DOCTYPE HTML>
<html>
    <?php
    echo $_SESSION['phone'];
    ?>
</html>

问题是会话变量($ _SESSION ['phone'])在m2.php中工作,但它不会显示在m3.php中。它什么也没显示。我的主要目的是在数据库中取电话号码和第一次检查。如果存在则显示信息,否则添加否。在数据库中以及其他详细信息,如姓名,地址等。我正在尝试使用会话,但上述问题并没有让我这样做。很长一段时间坚持这个。请帮助!

另外,如果我在m2.php中使用没有表单的相同内容,它可以很好地工作。

1 个答案:

答案 0 :(得分:0)

您应该在身体标签内写echo $_SESSION['phone'];

<?php session_start(); ?>

<!DOCTYPE HTML>
   <body>
        <?php
           echo $_SESSION['phone'];
        ?>
   </body>
</html>

要查看任何结果,您必须将其放在<body>标记