2015-09-27 148 views
-1

我对获得会话变量对会话变量不能被访问到不同的页面

我有三个PHP脚本 1. index.php的不同页面的工作问题(包括HTML格式)

<?php 
session_start(); 

if (isset($_POST['submit'])) { 
$_SESSION['billTo_email'] = $_POST['billTo_email']; 

} 
?> 
<form id = 'form_submit' method="post" action = "NetworkOnline.php"> 
<td><input type="text" name="billTo_email" id="f_name2" /></td> 
<td><input type="submit" name="submit" id="submit" value="Submit"/></td> 
</form> 
?> 
  • NetworkOnline.php

    <?php 
        session_start(); 
        $_SESSION['billTo_email'] = $_POST["billTo_email"]; 
        ?> 
    
        $f_name=$_POST["f_name"]; 
        $l_name=$_POST["l_name"]; 
        $billTo_country=$_POST["billTo_country"]; 
        $billTo_city=$_POST["billTo_city"]; 
        $billTo_state=$_POST["billTo_state"]; 
        $billTo_street1=$_POST["billTo_street1"]; 
        $billTo_pin=$_POST["billTo_pin"]; 
        $billTo_email = $_SESSION["billTo_email"]; 
    
  • response.php

    <?php 
    session_start(); 
    $_SESSION["billTo_email"] = $_POST["billTo_email"]; 
    ?> 
    
    <form name = "form1" method = "post" action="mail.php" > 
    <input type="hidden" name="order" id="order" value="<?php echo $order ?>" > 
    <input type="hidden" name="bank" id="bank" value="<?php echo $bank ?>" > 
    <input type="hidden" name="amount" id="amount" value="<?php echo $amount ?>" > 
    <input type = "test" name= "email" id ="email" value= "<?php echo $billTo_email ?>"> 
    <input type="submit" id="submit" value="submit" name="submit"> 
    </form> 
    
  • +0

    NetworkOnline.php上的结束标记位置错误。 –

    回答

    -1

    下面尝试,

    你关闭标签是错误的地方,

    的index.php

    <?php 
    session_start(); 
    
    if (isset($_POST['submit'])) { 
    $_SESSION['billTo_email'] = $_POST['billTo_email']; 
    } 
    ?> 
    <form id = 'form_submit' method="post" action = "NetworkOnline.php"> 
    <td><input type="text" name="billTo_email" id="f_name2" /></td> 
    <td><input type="submit" name="submit" id="submit" value="Submit"/></td> 
    </form> 
    

    NetworkOnline.php

    <?php 
        session_start(); 
    
        $_SESSION['billTo_email'] = $_POST["billTo_email"]; 
        $f_name=$_POST["f_name"]; 
        $l_name=$_POST["l_name"]; 
        $billTo_country=$_POST["billTo_country"]; 
        $billTo_city=$_POST["billTo_city"]; 
        $billTo_state=$_POST["billTo_state"]; 
        $billTo_street1=$_POST["billTo_street1"]; 
        $billTo_pin=$_POST["billTo_pin"]; 
        $billTo_email = $_SESSION["billTo_email"]; 
        ?> 
    

    response.php

    <?php 
    session_start(); 
    $_SESSION["billTo_email"] = $_POST["billTo_email"]; 
    ?> 
    
    <form name = "form1" method = "post" action="mail.php" > 
    <input type="hidden" name="order" id="order" value="<?php echo $order; ?>" > 
    <input type="hidden" name="bank" id="bank" value="<?php echo $bank; ?>" > 
    <input type="hidden" name="amount" id="amount" value="<?php echo $amount; ?>" > 
    <input type = "test" name= "email" id ="email" value= "<?php echo $billTo_email; ?>"> 
    <input type="submit" id="submit" value="submit" name="submit"> 
    </form> 
    
    +0

    如我在回答中提到的,不需要检查** if(isset($ _ POST ['submit']))**。 – SHAZ

    +0

    @SHAZ投票之前告诉我这段代码的危害.. – jlocker

    +0

    我没有downvote你的代码。 – SHAZ

    -1

    UPDATE:

    的index.php

    <form id = 'form_submit' method="post" action = "NetworkOnline.php"> 
        <td><input type="text" name="billTo_email" id="f_name2" /></td> 
        <td><input type="submit" name="submit" id="submit" value="Submit"/></td> 
    </form> 
    

    注:无需检查if (isset($_POST['submit'])) { ... }这里,因为index.php发送数据到NetworkOnline.php

    NetworkOnline.php

    <?php 
        ob_start(); // turn on output buffering 
        session_start(); 
        if(isset($_POST['billTo_email'])) { // work only if **billTo_email** has some value 
        $_SESSION['billTo_email'] = $_POST["billTo_email"]; 
        } 
    
        // ?> <-- remove this closing tag 
    
        $f_name=$_POST["f_name"]; // this line of code shows undefined variable, 
         //because in your index.php there is no any f_name field presnet. 
    
        // your remaining codes 
    
    
    ?> 
    
    +0

    ** Downvoting的原因** ????? – SHAZ

    +0

    未定义的索引:f_name – jlocker

    +0

    我明确提到** if()**条件上面检查变量具有价值。我把这两行代码,只是为了显示编码器**错位**结束标签。 @jlocker – SHAZ

    0

    试试这个, 的index.php:

    <html> 
    <form id = 'form_submit' method="post" action = "NetworkOnline.php"> 
    <td><input type="text" name="billTo_email" /></td> 
    <td><input type="submit" name="submit" id="submit" value="Submit"/></td> 
    </form> 
    </html> 
    

    NetworkOnline.php:

    <?php 
    session_start(); 
    $_SESSION['billTo_email'] = $_POST["billTo_email"]; 
    header('Location: response.php'); 
    ?> 
    

    response.php:

    <?php 
    session_start(); 
    $billTo_email=$_SESSION["billTo_email"] 
    ?> 
    <form name = "form1" method = "post" action="mail.php" > 
    <br /> 
    <br /> 
    <input type = "test" name= "email" value= "<?php echo $billTo_email ?>"> 
    <input type="submit" id="submit" value="submit" name="submit"> 
    </form> 
    
    +0

    感谢您的答案,但其仍然没有在这方面工作。 –

    相关问题