会议发布到下一页

时间:2014-12-17 11:32:16

标签: php html

<?php
session_start();

if (isset($_POST['Submit'])) { 
    $name = $_POST['name'];
 $_SESSION['name'] = $name;
 } // i need to pass this to next page $name.

?>
<html lang="en">
<head>
    <title>Aug Log In</title>
    <link rel="stylesheet" type="text/css" href="form1.css" media="screen"> 
</head>
<body align="center">
    <form action="test1.php" method="post">
    <div class="Upper_Img"><img src="http://localhost/augbanner.gif"/></div><!-- end of Upper_Img -->
    <div class="container">
    <h1> AUG SWIFT TEST </h1>
    <br>
        <label><a href="<?php echo $loginUrl;?>">LOG IN WITH FACEBOOK</a><label>
        <br>
        <br>
        <label><a href="">CHANGE FACEBOOK ACCOUNT</a></label>
        <br>
        <br>
        <label><input type="name" placeholder="name"/></label>
        <br>
        <br>
        <label><input type="email" placeholder="email"/></label>
        <br>
        <br>
        <input type="submit" name="submit" value="Sign Up"/>
    </form><!--end of form -->
    <div><!-- end of container -->
</body>
<footer>
</footer>
</html>

test1.php

<?php
   if(isset($_SESSION['name'])){
        echo "Welcome ".$_SESSION['name'];
    }

?>

我的意图是将$ name传递给text1.php,我仔细检查了一切。为什么我不能将$ name传递给下一页?我的HTML是不对的?

我尝试了这段代码,但仍无效:

$name = !empty($_POST['name']) ? $_POST['name'] : false; //get session passing data;

3 个答案:

答案 0 :(得分:2)

您需要将session_start()添加到下一页,但更重要的是,您需要向name添加input个属性:

<input type="text" placeholder="name" name="name"/>
...
<input type="email" placeholder="email" name="email"/>

答案 1 :(得分:0)

你需要把

session_start()

也在下一页。

这意味着:

<?php
   session_start();
   if(isset($_SESSION['name'])){
        echo "Welcome ".$_SESSION['name'];
    }

?>

答案 2 :(得分:0)

我想这就是你所期待的。这是代码:

<强>的index.php

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Aug Log In</title>
</head>
<body align="center">
    <form action="test.php" method="post"> // action - test.php
    <h1> AUG SWIFT TEST </h1><br>
       Username : <input type="text" name="uname" placeholder="name"/>
       <br><br>
       Email : <input type="email" name="email" placeholder="email"/>
        <br><br>
       <input type="submit" name="submit" value="Sign Up"/>
    </form>
</body>
</html>

您需要在name中添加input type属性,以便从test.php中获取值。

<强> test.php的

<?php
if (isset($_POST['submit'])) { // checks if user submits the form

    $u_name = $_POST['uname']; // Getting the username where user entered 
    $email = $_POST['email']; // Getting the email where user entered

    echo "Your username : " . $u_name ."<br/>";
    echo "Your email : " . $email;

}

?>

如果您想对任何页面使用username,只需添加

即可启动会话
 session_start() 

位于test.php&amp;

$_SESSION['name']=$u_name;
echo之前

。希望它有所帮助!